• iOS开发UUIView动画方法总结


    #动画设置 UIView动画实现
    @interface ViewController ()
    @property (weak, nonatomic) IBOutlet UIView *myView;
    @property (weak, nonatomic) IBOutlet UIView *redView;
    @end
    
    #pragma mark - UIView类实现动画
    
    #pragma mark - Animating Views with Block Object
    @implementation ViewController
    - (IBAction)handleViewOne:(id)sender {
    
     /* 方法1:Block语法的动画 */
         
        [UIView animateWithDuration:3 animations:^{
            
            /* 控件的属性发生改变 */
            self.myView.frame = CGRectMake(0, 100, 375, 200);
            self.myView.backgroundColor = [UIColor greenColor];
        
        }];
    
     /* 方法2 */
    
        [UIView animateWithDuration:3 animations:^{
            /* 动画开始的代码*/
            self.myView.frame = CGRectMake(0, 200, 375, 130);
            self.myView.backgroundColor = [UIColor cyanColor];
                
        } completion:^(BOOL finished) {
            
            /* 动画执行后的代码段 */
            self.myView.frame = CGRectMake(0, 58, 375, 130);
            
        }];
        
    /* 方法3 */
            /* options参数:动画相关参数,多个之间用 | 分开*/
        [UIView animateWithDuration:3 delay:1 options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse animations:^{
            
            /* 开始动画的View属性值 */
            self.myView.frame = CGRectMake(0, 200, 375, 130);
            self.myView.backgroundColor = [UIColor redColor];
                    
        } completion:^(BOOL finished) {
        }];
    
     /* 方法4 过渡动画效果 */
        
        [UIView transitionWithView:self.myView duration:3 options:UIViewAnimationOptionTransitionFlipFromLeft | UIViewAnimationOptionRepeat animations:^{
            
            self.myView.frame = CGRectMake(0, 200, 375, 130);
                            
        } completion:^(BOOL finished) {
            
        }];
        
     /* 方法5:从一个View过渡到另一个View */
        
        [UIView transitionFromView:self.myView toView:self.redView duration:3 options:UIViewAnimationOptionTransitionCurlUp completion:^(BOOL finished) {
            
        }];
    
     /* 方法6:设置弹簧(Spring)相关参数 */
            
        [UIView animateWithDuration:3 delay:0.5 usingSpringWithDamping:0.1 initialSpringVelocity:10 options:UIViewAnimationOptionRepeat animations:^{
                    
            /* 开始动画的状态 UIView的属性  */
            self.myView.frame = CGRectMake(0, 200, 375, 130);
            
        } completion:^(BOOL finished) {
            
            /* 结束动画 UIView的属性*/
            
        }];
    
     }
    
    #pragma mark - Animating Views
    - (IBAction)handleViewTow:(id)sender {
        
        /* 1,开始动画*/
        [UIView beginAnimations:@"FrameChange" context:nil];
                
        /* 2.动画设置 */
        
        [UIView setAnimationDuration:3];
        
        /** 重复的次数*/
        [UIView setAnimationRepeatCount:NSIntegerMax];
        
        /* 延迟动画 */
        
        [UIView setAnimationDelay:0.5];
        self.myView.frame = CGRectMake(0, 200, 375, 130);
        
        /* 3.提交动画 */
        [UIView commitAnimations];
           
    }
  • 相关阅读:
    Alpha冲刺
    Alpha冲刺
    抽奖系统(记一次未完成的教训)
    Alpha冲刺
    软件工程
    软工实践
    软工实践
    软工实践
    软工实践
    软工实践
  • 原文地址:https://www.cnblogs.com/WJJ-Dream/p/5817126.html
Copyright © 2020-2023  润新知