Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-27-2009, 06:27 PM   #1 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 171
dalson is on a distinguished road
Default UIButton Animation Problem

In my application, I have buttons that are moving across the screen, and the objective is to press the buttons as quickly as possible. The animation moves the buttons, but you cannot press the button until the button is in the final position of the animation. Any suggestions/fixes on how to make the button respond to touches while in motion?

Maybe there is an enable or something I am missing?
dalson is offline   Reply With Quote
Old 01-31-2012, 04:58 AM   #2 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 7
sudama is on a distinguished road
Default

Quote:
Originally Posted by dalson View Post
In my application, I have buttons that are moving across the screen, and the objective is to press the buttons as quickly as possible. The animation moves the buttons, but you cannot press the button until the button is in the final position of the animation. Any suggestions/fixes on how to make the button respond to touches while in motion?

Maybe there is an enable or something I am missing?

hello.
were you able to figure this out? I'm having the same problem...
sudama is offline   Reply With Quote
Old 01-31-2012, 06:08 AM   #3 (permalink)
Registered Member
 
Join Date: Oct 2011
Age: 25
Posts: 169
mer10 is on a distinguished road
Default

Are you using UIView animateWithDuration:delayptions:animations:compl etion: ,or updating it with a timer?
mer10 is offline   Reply With Quote
Old 02-01-2012, 12:35 AM   #4 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 7
sudama is on a distinguished road
Default

Quote:
Originally Posted by mer10 View Post
Are you using UIView animateWithDuration:delayptions:animations:compl etion: ,or updating it with a timer?
hi mer10,

I'm using animateWithDuration (or so I think :S)
below is the code Im using.

and, it's textfield, not button btw.

Code:
CGPoint newDownCenter = CGPointMake(135.0, 450); //20.0f + textField.center.y / 2.0f);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:6.0f];
textField.center = newDownCenter;
[UIView commitAnimations];


***
Right now it wouldn't work (meaning I'm not able to click) so what I do is use a timer and make it move towards the desired place.

Code:
//vertical
if (desiredX != textField.center.x) {
if (desiredX > textField.center.x) {
newLocationX = textField.center.x + 1;
}else{
newLocationX = textField.center.x - 1;
}
}
//horizontal
if (desiredY != textField.center.y) {
newLocationY = textField.center.y + 1;
}

textField.center = CGPointMake(newLocationX, newLocationY);

---
pretty awful code. but this is the only way i was able to make the textfield move and enabled at the same time...
any other suggestions would be very appreciated..
sudama is offline   Reply With Quote
Old 02-01-2012, 07:12 AM   #5 (permalink)
Registered Member
 
Join Date: Oct 2011
Age: 25
Posts: 169
mer10 is on a distinguished road
Default

Quote:
Originally Posted by sudama View Post
hi mer10,

I'm using animateWithDuration (or so I think :S)
below is the code Im using.

and, it's textfield, not button btw.

Code:
CGPoint newDownCenter = CGPointMake(135.0, 450); //20.0f + textField.center.y / 2.0f);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:6.0f];
textField.center = newDownCenter;
[UIView commitAnimations];


***
Right now it wouldn't work (meaning I'm not able to click) so what I do is use a timer and make it move towards the desired place.

Code:
//vertical
if (desiredX != textField.center.x) {
if (desiredX > textField.center.x) {
newLocationX = textField.center.x + 1;
}else{
newLocationX = textField.center.x - 1;
}
}
//horizontal
if (desiredY != textField.center.y) {
newLocationY = textField.center.y + 1;
}

textField.center = CGPointMake(newLocationX, newLocationY);

---
pretty awful code. but this is the only way i was able to make the textfield move and enabled at the same time...
any other suggestions would be very appreciated..
I've seen worse.

I'd recommend trying using the Apple endorsed method animateWithDuration:delayptions:animations:compl etion: rather than the depreciated methods. If you specify UIViewAnimationOptionAllowUserInteraction in the options you should be able to click it.
mer10 is offline   Reply With Quote
Old 02-01-2012, 07:41 AM   #6 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by sudama View Post
hi mer10,

I'm using animateWithDuration (or so I think :S)
below is the code Im using.

and, it's textfield, not button btw.

Code:
CGPoint newDownCenter = CGPointMake(135.0, 450); //20.0f + textField.center.y / 2.0f);
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:6.0f];
textField.center = newDownCenter;
[UIView commitAnimations];


---snip---

pretty awful code. but this is the only way i was able to make the textfield move and enabled at the same time...
any other suggestions would be very appreciated..
The system turns off user interaction on objects while they are being animated. You can ask it not to do that if you use block-style animation, ( with the method animateWithDuration:delayptions:animations:compl etion: ) as the other poster suggests:

Code:
  [UIView animateWithDuration: 6.0f 
  delay: 0
  options: UIViewAnimationOptionAllowUserInteraction
  animations: ^
  {
    textField.center = newDownCenter;
  }
  completion: nil
  ];
The key is the options parameter UIViewAnimationOptionAllowUserInteraction. That tells the system to let the user interact with the object during animation.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.

Last edited by Duncan C; 02-01-2012 at 08:20 AM.
Duncan C is online now   Reply With Quote
Old 02-01-2012, 08:23 AM   #7 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by mer10 View Post
I've seen worse.

I'd recommend trying using the Apple endorsed method animateWithDuration:delayptions:animations:compl etion: rather than the depreciated methods. If you specify UIViewAnimationOptionAllowUserInteraction in the options you should be able to click it.


The beginAnimations...commitAnimations animation style isn't deprecated, but it is discouraged, whatever that means. Here is the relevant quote from the docs.

Code:
beginAnimations:context:
Marks the beginning of a begin/commit animation block.

Use of this method is discouraged in iOS 4.0 and later. You should use the block-based animation methods to specify your animations instead.
I still use beginAnimations...commitAnimations style animations for code that's targeted to OS versions <4.0.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is online now   Reply With Quote
Old 02-01-2012, 09:11 PM   #8 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 7
sudama is on a distinguished road
Default Thanks!

mer10, Duncan,

Thanks! You can't imagine how much i spent on google with this problem. X(

I tried using the animateWithDuration as you both said, but unfortunately, it gave me the "uiview may not able to respond to...." warning..
apparently my OS version is too old. :/
(sorry, im a windows user most of the time... :S)

Anyways, Imma gonna try to update my OS and try those codes! But I did some research myself, Im sure it's gonna work!^^ Thanks so much!!
sudama is offline   Reply With Quote
Old 02-02-2012, 05:24 AM   #9 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by sudama View Post
mer10, Duncan,

Thanks! You can't imagine how much i spent on google with this problem. X(

I tried using the animateWithDuration as you both said, but unfortunately, it gave me the "uiview may not able to respond to...." warning..
apparently my OS version is too old. :/
(sorry, im a windows user most of the time... :S)

Anyways, Imma gonna try to update my OS and try those codes! But I did some research myself, Im sure it's gonna work!^^ Thanks so much!!
Yes, the animateWithDuration: methods require iOS 4.0 or later.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is online now   Reply With Quote
Old 02-03-2012, 09:34 PM   #10 (permalink)
Registered Member
 
Join Date: Oct 2009
Posts: 7
sudama is on a distinguished road
Default Still not working... :/

okay, i tried using animateWithDuration both with textfield and button but it's still not working.

Code:
[UIView animateWithDuration:10.0f
delay:0.5f
options:
UIViewAnimationOptionAllowUserInteraction
animations:^{
button.center = CGPointMake(135, 450);
}
completion:nil];


----
I did some researching, and apparently "The touchable part of the button will not coincide with the button's visible frame when it is being animated."
(according to the link below).
iphone - UIButton can't be touched while animated with UIView animateWithDuration - Stack Overflow

anyways, my crappy code up works, so i think I'll stick to that.. and hopefully apple store won't reject my app >.<

Thanks for the info anyways!^^
sudama is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 342
14 members and 328 guests
akacaj, alexP, ClerurcifeDer, Domele, Duncan C, givensur, GraffitiCircus, guusleijsten, JmayLive, NetGuru, NSString, Paul Slocum, Punkjumper, Sloshmonster
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,114
Posts: 402,883
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:50 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0