• ios中自定义图层


    图层和VIEW的区别

    1;view不具备显示功能,是因view内部有一个图层,才能显示出来

    2:图层不具备事件功能,VIEW继承UIRespone具有处理事件功能

    3:自定义的图层有一个影式动画,VIEW中图层没有隐式动画(影式动画:改变图层的某个属性,会发生动画,uiview内部图层没有影视动画)

    自定义图层

    #import <QuartzCore/QuartzCore.h>
    
    @interface MJViewController ()
    
    @end
    
    @implementation MJViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        CALayer *layer = [CALayer layer];
        layer.bounds = CGRectMake(0, 0, 100, 100);
        // position默认的含义:指当前图层的中点
        layer.position = CGPointMake(100, 100);
        layer.backgroundColor = [UIColor redColor].CGColor;
        layer.borderWidth = 5;
        layer.borderColor = [UIColor blueColor].CGColor;
        
        // 显示的内容(图片)
        layer.contents = (id)[UIImage imageNamed:@"lufy.png"].CGImage;
        [self.view.layer addSublayer:layer];
    }

     自定义calayer的影式动画

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        CALayer *layer = [CALayer layer];
        layer.bounds = CGRectMake(100, 100, 100, 100);
        layer.position = CGPointMake(50, 50);
        layer.backgroundColor = [UIColor redColor].CGColor;
        [self.view.layer addSublayer:layer];
        _layer = layer;
    }
    
    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        //self.myview.layer.position = CGPointMake(200, 200);
        
        // 可以参与隐式动画的属性:可动画属性
        [CATransaction begin];
        // 关闭隐式动画
        [CATransaction setDisableActions:YES];
        
        _layer.position = CGPointMake(200, 200);
        
        [CATransaction commit];
        
        //_layer.bounds = CGRectMake(0, 0, 20, 20);
        
        //_layer.borderWidth = 20;
        //_layer.borderColor = [UIColor blueColor].CGColor;
        
       // _layer.backgroundColor = [UIColor blueColor].CGColor;
    }

     怎样操作 自定义图层中影视动画属性

    xcode---window --->organizer-->在搜索框内搜索“animatable”-->在搜索结果中找到”CaLayer animable propertiy“

  • 相关阅读:
    idea 找不到包或找不到符号
    JOISC部分题解
    欧拉数学习笔记
    [清华集训2017]生成树计数
    [ZJOI2019]开关
    【题解】CF817E Choosing The Commander
    CSP-S 2020游记
    【学习笔记】线段树合并
    【题解】[IOI2005]Riv 河流
    【题解】哈希冲突
  • 原文地址:https://www.cnblogs.com/gcb999/p/3189183.html
Copyright © 2020-2023  润新知