zoukankan      html  css  js  c++  java
  • 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“

  • 相关阅读:
    OSPF LSA过滤简述 转自 huawei企业论坛
    distribute-list分发列表 转自 红茶三杯sina blog
    rip 协议号
    Ping命令的工作过程及单向Ping通的原因
    Cisco路由器故障诊断技术专题
    self-introduction for bleum (not in use)
    智能手环是什么情况
    页面置换算法 FIFO NUR LRU LFU
    慢慢来----由易语言想到的一点点
    ssh免密登录
  • 原文地址:https://www.cnblogs.com/gcb999/p/3189183.html
Copyright © 2011-2022 走看看