开发者

iphone:objective c: UIView animation?

开发者 https://www.devze.com 2023-03-12 09:45 出处:网络
I have read apple documentation: http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/AnimatingViews/AnimatingViews.html#//apple_ref/doc/uid/TP40009503-CH6-SW1

I have read apple documentation: http://developer.apple.com/library/ios/#documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/AnimatingViews/AnimatingViews.html#//apple_ref/doc/uid/TP40009503-CH6-SW1

For iOS3.0 and earlier, using this:

Method1:

[UIView beginAnimations:@"ShowHideVie开发者_开发技巧w" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
...

The new one, iOS4, can do this:

Method2:

[UIView animateWithDuration:1.0 animations:^{
    firstView.alpha = 0.0;
    secondView.alpha = 1.0;
}];

Q1. What I want to know is, in earlier method, they have this "ShowHideView" in beginAnimations, is that method a built-in one?

Q2. Are there any others built-in methods for animation in beginAnimations? If yes, where can I find all those methods?

Q3. And lastly, can I use those methods in latter method(method2) call?


You can get all the answers to your questions in the UIView Class Reference.

Q1: ShowHideView, as you have it, is not a method at all. It is simply an "application-supplied identifier for the animations". In reality, you don't need it. When I use this method, I just use NULL instead of supplying an identifier there.

Q2: You don't set animations in the beginAnimations:context: call. You even illustrate it there by calling setAnimationCurve. You can set the animations from this typedef.

Q3: Again, you don't declare animation types in animateWithDuration:animations: call either. Utilize setAnimationCurve: to do that in that example as well.


Blocks have the benefit of being able to nest the animations (in a queue almost) using the [UIView animateWithDuration:animations:completion:] selector. You can nest another call to this method inside the finished block like so:

[UIView animateWithDuration:1.0 animations:^{  
   // your first animations
} completion:^(BOOL finished) {
   [UIView animateWithDuration:1.0 animations:^{
         // more animations
     } completion:^(BOOL finished) {
         // ... maybe even more
     }]
 }]

I abuse this in my code and find it much easier than using the beginAnimations/commitAnimations code. And, with iOS 5 approaching, the days of needing to support iOS 3.x are slipping away.

0

精彩评论

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

关注公众号