PDA

View Full Version : Animation a UIButton while animating a View - Ipad




ashwinr87
May 24, 2011, 02:29 PM
Hi,

I am facing a problem in animation.

So right now in my app, I have a subview which has a close button. When the close button is pressed, a curl down animation occurs showing the previous view. That is working properly. I perform the curl down closing animation by passing a notification to the NSNotificationCenter like this [[NSNotificationCenter defaultCenter] postNotificationName:notificationName object:self];

Now I wanted to apply an animation to the close button itself so that when I press the close button, it would perform an animation as well as the curl down animation would occur. So the way I do it is by the following code

[UIView transitionWithView:self.view.superview duration:1
options:UIViewAnimationOptionCurveEaseIn
animations:^ { closeButton.frame = CGRectMake(500, 15, 100, 40); }
completion:nil];

Where previously the closeButton.frame had the value of (580,15,100,40) so the animation would be like the image was moving from right to left from 580 to 500.

So what happens when I run the code is that when I press the close button, the close button animation does not happen but the curl down animation occurs. So for testing when I commented out the code where I post the notification, the close button animation works perfectly but the curl down animation does not happen nor does the previous view come up ( since I do not send a notification which would cause the view to close).

I would like to know what is going wrong here and why it does not allow 2 animations to occur at the same time.



Shawnpk
May 24, 2011, 05:45 PM
If I remember correctly, when you call more than one animation in a method or action, only the last animation gets called. You can verify this by switching around your animation calls. I can't remember off hand how to make more than one animation fire, but I'll look it up and get back to you.

EDIT: Maybe this will help you:

http://developer.apple.com/library/ios/ipad/#documentation/windowsviews/conceptual/viewpg_iphoneos/animatingviews/animatingviews.html

ashwinr87
May 25, 2011, 09:01 AM
thanks for the link.. will check it out and see if I can get something to work...

If I remember correctly, when you call more than one animation in a method or action, only the last animation gets called. You can verify this by switching around your animation calls. I can't remember off hand how to make more than one animation fire, but I'll look it up and get back to you.

EDIT: Maybe this will help you:

http://developer.apple.com/library/ios/ipad/#documentation/windowsviews/conceptual/viewpg_iphoneos/animatingviews/animatingviews.html

ashwinr87
May 25, 2011, 09:56 AM
Here is how I solved it...

many thanks to Shawnpk for pointing me at the right direction

I used the nested animation using blocks where I included the code for the curl down close view in the completion part of the close button animation...

[UIView transitionWithView:self.view.superview duration:1
options:UIViewAnimationOptionCurveEaseIn
animations:^ {
popContents.closeButton.frame = CGRectMake(500, 15, 100, 40); }
completion:^(BOOL finished){
[UIView transitionWithView:self.view.superview duration:1
options:UIViewAnimationOptionTransitionCurlDown
animations:^ {
popContents = nil;
[popContents.view removeFromSuperview];
[ovController.view removeFromSuperview];
ovController = nil; }
completion:nil];
}];