UIView 动画总结

UIViewAnimation

这是最基本的动画

- (void)startAnimating{
    
                                                  //__bridge 不移交控制权
    [UIView beginAnimations:@"animation" context:(__bridge void *)(self)];
    
    [UIView setAnimationDuration:0.4];
    _square.center = CGPointMake(_square.center.x + 100, _square.center.y);
    [UIView setAnimationDelegate:self];
    
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
    [UIView commitAnimations];
    
}

UIViewAnimationWithBlocks

对基本UIViewAnimation的block封装

- (void)startBlockAnimation{

    UIViewAnimationOptions options = UIViewAnimationOptionAutoreverse | UIViewAnimationOptionTransitionCrossDissolve ;
    
    [UIView animateWithDuration:0.4 delay:0 options:options animations:^{
        
        _square.center = CGPointMake(_square.center.x + 100, _square.center.y);
        
    } completion:^(BOOL finished) {
        
    }];
    
    
}

+ (void)transitionWithView:(UIView *)view duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^ __nullable)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); //翻转动画

UIViewKeyframeAnimations

设置动画里面的几个关键帧, 系统自动构建出完整的动画


//实现_square 按正方形规矩运动
- (void)startKeyFrameAnimation{
    
    UIViewKeyframeAnimationOptions options = UIViewKeyframeAnimationOptionRepeat;
    
    [UIView animateKeyframesWithDuration:4 delay:0 options:options animations:^{
        
        
        double frameDuration = 1.0 / 4;
        
        [UIView addKeyframeWithRelativeStartTime:0 relativeDuration:frameDuration animations:^{
            
            _square.center = CGPointMake(_square.center.x + 100, _square.center.y);
            
        }];
        
        [UIView addKeyframeWithRelativeStartTime:frameDuration  relativeDuration:frameDuration animations:^{
            
            _square.center = CGPointMake(_square.center.x , _square.center.y + 100);
            
        }];
        
        [UIView addKeyframeWithRelativeStartTime:frameDuration * 2 relativeDuration:frameDuration animations:^{
            
            _square.center = CGPointMake(_square.center.x - 100, _square.center.y);
            
        }];
        
        [UIView addKeyframeWithRelativeStartTime:frameDuration * 3 relativeDuration:frameDuration animations:^{
            
            _square.center = CGPointMake(_square.center.x , _square.center.y -100);
            
        }];
        
        
        
    } completion:nil];
    
    
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,290评论 4 61
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 175,827评论 25 709
  • “毁掉我们的,不是我们憎恨的东西,恰恰是我们热爱的东西!” “一切公众话语权日渐以娱乐的方式出现,并成为一种文化精...
    dono阅读 845评论 0 0
  • 关于根组件 关于组件 关于click 关于img 关于过渡动画 关于v-for 关于class 上一篇: vue2...
    守心向暖阅读 1,469评论 0 0
  • 常遇见那些“真性情,没礼貌”的人。 一大早,L绅士推开办公室的门就对我说:怎么不把地扫了?你想想看,等领导来了...
    赤脚光头阅读 2,593评论 2 3