zoukankan      html  css  js  c++  java
  • [UIView beginAnimations:context:]与[UIView animateWithDuration:animations:]值得注意的一个区别

    原文链接:http://longtimenoc.com/archives/uiview-beginanimationscontext%E4%B8%8Euiview-animatewithdurationanimations%E5%80%BC%E5%BE%97%E6%B3%A8%E6%84%8F%E7%9A%84%E4%B8%80%E4%B8%AA%E5%8C%BA%E5%88%AB


    看过官方文档的都知道,官方推荐在iOS4以后使用[UIView animateWithDuration:animations:],而不是原来的[UIView beginAnimations:context:],来完成动画,虽然二者功能几乎完全相同,但使用前者在一些情况下会方便不少,这些内容可以参考官方文档View Programming Guide For iOS的Animation一节.
    二者有一个值得新手注意的区别就是[UIView animateWithDuration:animations:]默认会禁止触摸,手势等的响应,这可以通过设置option选项来解决(直接引用StackOverFlow的一段了):

    1. UIViewAnimationOptions options = UIViewAnimationCurveLinear | UIViewAnimationOptionAllowUserInteraction;  
    2.    
    3. [UIView animateWithDuration:0.2 delay:0.0 options:options animations:^  
    4.  {  
    5.      highlightView.alpha = 1.0;  
    6.    
    7.  } completion:nil];  

    就是这么一点事儿,害我走了不少弯路(我也是新手哈),在这里写一下,提示一下有可能遇到同样问题的人.

     

    1. [UIView animateWithDuration:duration  
    2.                           delay:0.0  
    3.                         options:UIViewAnimationCurveEaseInOut //设置动画类型  
    4.                      animations:^{  
    5.                          //开始动画  
    6.                          [self updateArrowBtnTitle:YES];  
    7.                          rotateView.transform = CGAffineTransformMakeRotation((stickToDegrees/180)*M_PI);  
    8.                      }  
    9.                      completion:^(BOOL finished){  
    10.                          // 动画结束时的处理  
    11.                      }];  

     

    [UIView animateWithDuration:] 方法仅支持ios4.0及以上版本。如果要兼容以前的版本的话,还是需要使用 [UIView beginAnimation:] 方法

      1. [UIView beginAnimations:nil context:nil];  
      2.     // fade out  
      3.     helpImageBtn.alpha = 0.0f;  
      4.     // set animation did stop selector  
      5.     [UIView setAnimationDelegate:self];  
      6.     [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];  
      7.     [UIView commitAnimations];  
      8.   
      9.    - (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {  
      10.     if (self.retainedHelpImageBtn.superview) //先判断父视图再执行视图移除  
      11.         [self.retainedHelpImageBtn removeFromSuperview];  
      12.    }  
  • 相关阅读:
    林正英电影之我见
    雕虫小技,颇感羞愧。
    简单地求最大公约数
    大声喊:我现在不喜欢编程!
    简单递归题,核反应堆中有α和β两种粒子...
    递归简单题2
    Java接口和抽象类的理解
    如何入门计算机高级程序语言,进化菜鸟程序员
    memcached安装报错 error while loading shared libraries: libevent2.0.so.5: cannot open shared object file: No such file or directory解决
    linux mount 过程
  • 原文地址:https://www.cnblogs.com/heyonggang/p/3494468.html
Copyright © 2011-2022 走看看