开发者

Animating UIView problem (matching the expanding animation to the shrinking animation)

I'm trying to animate a UIView so that it can grow larger when tapping a button and shrinks down to its original size by tapping the button again.

I do this by adjusting frame to its new size and origin and running the code below.

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
self.theView.frame = frame;
[UIView commitAnimations];

When animating to a bigger size the animation is how it should be. But when animating to its original size (smaller) the view is re-sized instantly and then animated to its designated location.

What I need is that the resizing to the sm开发者_高级运维aller frame is animated as well.

I've tried adjusting the autoresizingMask as well, but that didn't change anything.

Hope someone can help.

thanks.


Michiel, Raj,

I made a youtube tutorial showing how to make views expand and shrink like in the facebook iPhone app.

Hope it can be of some help: How to make expanding/shrinking views on iPhone SDK

Adam


Try this

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationRepeatAutoreverses:YES];
self.theView.frame = frame;
[UIView commitAnimations];

In response to comment;

If you want to control animation reverse, have a flag like BOOL isbig and set it in app launch to NO, then toggle it in every button tap, then check it if it is YES or NO, and according to the result call a method. If NO, call your code, if not call the code again but this time set the frame to the original size.

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
self.theView.frame = originalFrame;
[UIView commitAnimations];


I could solve the problem by suggestion found in other thread, it has its own limitations though. I have posted the code in the same thread where the solution was suggested:

UIView scaling during animation


I worked around this problem when releasing my app by just removing the animation. It kept bugging me in the back of my mind, so just this week I thought that maybe by using the center property and the size instead of the origin it would make a difference.

So I decided to test this out. Guess what. The problem doesn't occur when using sdk 4.x

Thanks all for trying to help me out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜