天天看點

[UIView beginAnimations:context:]與[UIView animateWithDuration:animations:]值得注意的一個差別

看過官方文檔的都知道,官方推薦在iOS4以後使用[UIView animateWithDuration:animations:],而不是原來的[UIView beginAnimations:context:],來完成動畫,雖然二者功能幾乎完全相同,但使用前者在一些情況下會友善不少,這些内容可以參考官方文檔View Programming Guide For iOS的Animation一節.

二者有一個值得新手注意的差別就是[UIView animateWithDuration:animations:]預設會禁止觸摸,手勢等的響應,這可以通過設定option選項來解決(直接引用StackOverFlow的一段了):

UIViewAnimationOptions options = UIViewAnimationCurveLinear | UIViewAnimationOptionAllowUserInteraction;  

[UIView animateWithDuration:0.2 delay:0.0 options:options animations:^  

 {  

     highlightView.alpha = 1.0;  

 } completion:nil];  

就是這麼一點事兒,害我走了不少彎路(我也是新手哈),在這裡寫一下,提示一下有可能遇到同樣問題的人.

[UIView animateWithDuration:duration  

                          delay:0.0  

                        options:UIViewAnimationCurveEaseInOut //設定動畫類型  

                     animations:^{  

                         //開始動畫  

                         [self updateArrowBtnTitle:YES];  

                         rotateView.transform = CGAffineTransformMakeRotation((stickToDegrees/180)*M_PI);  

                     }  

                     completion:^(BOOL finished){  

                         // 動畫結束時的處理  

                     }];  

[UIView animateWithDuration:] 方法僅支援ios4.0及以上版本。如果要相容以前的版本的話,還是需要使用 [UIView beginAnimation:] 方法

[UIView beginAnimations:nil context:nil];  

    // fade out  

    helpImageBtn.alpha = 0.0f;  

    // set animation did stop selector  

    [UIView setAnimationDelegate:self];  

    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];  

    [UIView commitAnimations];  

   - (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {  

    if (self.retainedHelpImageBtn.superview) //先判斷父視圖再執行視圖移除  

        [self.retainedHelpImageBtn removeFromSuperview];  

   }  

[UIView beginAnimations:context:]與[UIView animateWithDuration:animations:]值得注意的一個差別

本文轉自夏雪冬日部落格園部落格,原文連結:http://www.cnblogs.com/heyonggang/p/3494468.html,如需轉載請自行聯系原作者