zoukankan      html  css  js  c++  java
  • UIView封装的动画

    一:view实现动画和layer实现动画的区别

        一般动画是操作在view上面的,对layer上面的动画进行了封装,比较的简单

        图层动画缺点:1、会反弹;2、看到的动画都是假象,图层的属性一直没有变过,所以会反弹

        图层动画都是假象,在动画执行过程中,图层的position属性一直没有改变过,图层的任何属性都不会损失

         开发中图层动画用的比较多的是转场动画,其他的一般使用view动画,尽量使用view的动画,view做不了的动画使用layer来做,比如抖动效果view动画不好做,就使用图层来做

        图层动画比较有价值的是:CAKeyframeAnimation帧动画和CATransition转场动画,CABasicAnimation没有太大的用处(是假象,不是真的改变了layer的相关属性)

    二、layer动画

    #pragma make layer动画
    - (void)testLayerAnimation
    {
        CABasicAnimation *anim = [CABasicAnimation animation];
        anim.keyPath = @"position";
        anim.toValue = [NSValue valueWithCGPoint:CGPointMake(200, 100)];
        anim.duration = 2.0;
        //layer的position属性值是没有变动的,结束的时候需要手动的留着最后一次的动画状态
        anim.removedOnCompletion = NO;
        anim.fillMode = kCAFillModeForwards;
        
        [self.myview.layer addAnimation:anim forKey:nil];
        
    }

    三、view动画方法一,比较的麻烦,不采用,了解

    #pragma make view动画
    - (void)testViewAnimation1
    {
        [UIView beginAnimations:nil context:nil];
        //这个动画监听动画结束,动画结束的时候调用代理(当前控制器)的animationStop
        //比较的麻烦
        [UIView setAnimationDelegate:self];
        [UIView setAnimationDidStopSelector:@selector(animationStop)];
        self.myview.center = CGPointMake(200, 200);
        [UIView commitAnimations];    
    }
    - (void)animationStop
    {
        //动画执行结束的时候调用
    }

    四、block方法实现view动画

    - (void)testViewAnimation2
    {
    //    block动画,相对testViewAnimation1方法比较简单
        [UIView animateWithDuration:1.0 animations:^{
            self.myview.center = CGPointMake(200, 200);
    
        } completion:^(BOOL finished) {
            
        }];
        
    }

    五、view实现转场动画

    @property (weak, nonatomic) IBOutlet UIImageView *iconView;
    
    @property (nonatomic, assign) int  index;//标记当前图片的下标
    
    - (void)testViewAnimation3
    {
        self.index++;
        if (self.index == 3) {
            self.index = 0;
        }
        NSString *filename = [NSString stringWithFormat:@"%d.jpg",self.index + 1];
        self.iconView.image = [UIImage imageNamed:filename];
        
         //view实现转场动画
        [UIView transitionWithView:self.iconView duration:1.0 options:UIViewAnimationOptionTransitionFlipFromTop animations:^{
            //animations,转场动画的时候还可以做其他的动画
        } completion:nil];
        
    }
  • 相关阅读:
    PHP设计模式——单例模式
    PHP设计模式——工厂模式
    远程备份脚本
    支持UEFI和LEGACY的多系统安装U盘
    minikube部署kubernetes学习环境
    获取kubernetes镜像
    Jenkins常用插件
    不想用ubuntu了,换个系统manjaro
    openstack stein部署手册 10. 创建实例
    openstack stein部署手册 10. horzion
  • 原文地址:https://www.cnblogs.com/yipingios/p/4505901.html
Copyright © 2011-2022 走看看