zoukankan      html  css  js  c++  java
  • IOS 隐式动画(非Root Layer)

    每一个UIView内部都默认关联着一个CALayer,我们可用称这个LayerRoot Layer(根 层)
    所有的Root Layer,也就是手动创建的CALayer对象,都存在着隐式动画
    什么是隐式动画?
    当对Root Layer的部分属性进行修改时,默认会自动产生一些动画效果
    而这些属性称为Animatable Properties(可动画属性)
    列举几个常见的Animatable Properties:

    bounds:用于设置CALayer的宽度和高度。修改这个属性会产生缩放动画

    backgroundColor:用于设置CALayer的背景色。修改这个属性会产生背景色的渐变动画

    position:用于设置CALayer的位置。修改这个属性会产生平移动画

     

    隐式动画

     可以通过动画事务(CATransaction)关闭默认的隐式动画效果

    [CATransaction begin];
    [CATransaction setDisableActions:YES];
    self.myview.layer.position = CGPointMake(10, 10);
    [CATransaction commit];

    @interface NJViewController ()
    
    @property (nonatomic, strong) CALayer *layer;
    @end
    
    @implementation NJViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        
        CALayer *layer = [CALayer layer];
        layer.backgroundColor = [UIColor redColor].CGColor;
        layer.bounds = CGRectMake(0, 0, 100, 100);
        layer.anchorPoint = CGPointZero;
        [self.view.layer addSublayer:layer];
        self.layer = layer;
    }
    
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
    {
        // 关闭隐式动画
    //    [CATransaction begin];
    //    [CATransaction setDisableActions:YES];
        
        // 隐式动画
        self.layer.backgroundColor = [UIColor greenColor].CGColor;
    //    self.layer.bounds = CGRectMake(0, 0, 200, 200);
        self.layer.position = CGPointMake(200, 200);
        //    self.layer.position // 如何查看CALayer的某个属性是否支持隐式动画, 查看头文件是否有 Animatable
        
    //    [CATransaction commit];
        
    }

     

  • 相关阅读:
    HDU2059(龟兔赛跑)
    pat 1012 The Best Rank
    pat 1010 Radix
    pat 1007 Maximum Subsequence Sum
    pat 1005 Sign In and Sign Out
    pat 1005 Spell It Right
    pat 1004 Counting Leaves
    1003 Emergency
    第7章 输入/输出系统
    第六章 总线
  • 原文地址:https://www.cnblogs.com/liuwj/p/6599362.html
Copyright © 2011-2022 走看看