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“

  • 相关阅读:
    express中session的基本使用
    MongoDB 索引 和 explain 的使用
    MongoDB 数据库创建删除、表(集合) 创建删除、数据增删改查
    node fs模块
    k30s刷入国际rom
    基于webpack项目的全局变量
    nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)
    html手写板
    vue常用配置
    vue组件库从创建到发行和使用
  • 原文地址:https://www.cnblogs.com/gcb999/p/3189183.html
Copyright © 2011-2022 走看看