#import "ViewController.h"

@interface ViewController ()
@property(nonatomic,strong)CALayer *calayer;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIButton *btn =[UIButton buttonWithType:UIButtonTypeSystem];
    btn.frame=CGRectMake(100, 100, 100, 50) ;
    btn.tag=1;
    [btn setTitle:@"隐式事务按钮" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [btn setTintColor:[UIColor blackColor]];
    [btn addTarget:self action:@selector(btnclick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];

    UIButton *btn1 =[UIButton buttonWithType:UIButtonTypeSystem];
    btn1.frame=CGRectMake(200, 100, 100, 50) ;
    btn1.tag=2;
    [btn1 setTitle:@"显式事务按钮" forState:UIControlStateNormal];
    [btn1 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [btn1 setTintColor:[UIColor blackColor]];
    [btn1 addTarget:self action:@selector(btnclick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn1];

//    CATransaction 事务类,可以对多个layer的属性同时进行修改.它分隐式事务,和显式事务.
//    区分隐式动画和隐式事务:隐式动画通过隐式事务实现动画 。修改Calayer的属性属于隐式事务
//    区分显式动画和显式事务:显式动画有多种实现方式,显式事务是一种实现显式动画的方式。
     //隐式事务
    self.calayer=[CALayer layer];
    self.calayer.bounds=CGRectMake(150, 150, 100, 100);
    self.calayer.position=CGPointMake(100, 200);
    self.calayer.backgroundColor=[UIColor redColor].CGColor;
    self.calayer.borderColor = [UIColor blackColor].CGColor;
    self.calayer.opacity = 1.0f;
    [self.view.layer addSublayer:self.calayer];
    [super viewDidLoad];

}
-(void)btnclick:(id)sender
{
    UIButton *btn=(UIButton *)sender;
    if (btn.tag==1) {
        [CATransaction setDisableActions:YES];
        self.calayer.cornerRadius = (self.calayer.cornerRadius == 0.0f) ? 30.0f : 0.0f;
        self.calayer.opacity = (self.calayer.opacity == 1.0f) ? 0.5f : 1.0f;
    }
    else
    {
        //事务嵌套
        [CATransaction begin];
        [CATransaction begin];
        [CATransaction setDisableActions:YES];
        self.calayer.opacity = (self.calayer.opacity == 1.0f) ? 0.5f : 1.0f;
        [CATransaction commit];
        //上面的动画并不会立即执行,需要等最外层的commit
        [NSThread sleepForTimeInterval:3];
        //显式事务默认开启动画效果,kCFBooleanTrue关闭
        [CATransaction setValue:(id)kCFBooleanFalse
                         forKey:kCATransactionDisableActions];
        //动画执行时间
        [CATransaction setValue:[NSNumber numberWithFloat:10.0f] forKey:kCATransactionAnimationDuration];
        //[CATransaction setAnimationDuration:[NSNumber numberWithFloat:5.0f]];
        self.calayer.cornerRadius = (self.calayer.cornerRadius == 0.0f) ? 30.0f : 0.0f;
        [CATransaction commit];

    }

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

CATransaction(参考其他博客敲)的更多相关文章

  1. 必应缤纷桌面的必应助手-软件分析和用户市场需求之-----二.体验部分 Ryan Mao (毛宇11061171) (完整版本请参考团队博客)

    <必应缤纷桌面的必应助手> 2.体验部分 Ryan Mao (毛宇11061171) (完整分析报告请参考团队博客http://www.cnblogs.com/Z-XML/) 我花了2天的 ...

  2. 解决SkyP2M工程常见问题所参考的博客汇总

    工程是基于64位的 1 Error 26 error C2491: 'HUDManager::_viewport' : definition of dllimport static data memb ...

  3. ADB命令详解及大全( 声明:此文是参考大佬博客所做的笔记!)

    adb是什么? adb的全称为Android Debug Bridge,就是起到调试桥的作用.通过adb我们可以在Eclipse中方面通过DDMS来调试Android程序,说白了就是debug工具.a ...

  4. 对学长所谓“改变世界的游戏”《shield star》的运行感想-毛宇部分(完整版本请参考团队博客)

    对于学长项目<shield star>的思考和看法: Ryan Mao ((毛宇)  110616-11061171 试用了一下学长黄杨等人开发的<shield star>游戏 ...

  5. gazebo 7.0 升级到7.15 参考他人博客

    gazebo 7.0 升级到7.14 网址:https://blog.csdn.net/riancy_riancy/article/details/84568322 编译后遇到报错 ,解决问题的网址: ...

  6. 各大IT技术博客排行榜

    cnblogs 积分排名前3000名 http://www.cnblogs.com/ 左侧有推荐博客排行 cppblog http://www.cppblog.com/AllBloggers.aspx ...

  7. (Beta)Let's-Beta阶段展示博客

    康家华:http://www.cnblogs.com/AmazingMax/ 马阿姨:http://www.cnblogs.com/oushihuahua/ 刘彦熙:http://www.cnblog ...

  8. oracle 常用博客网址

    使用oradebug修改数据库scn – 提供专业ORACLE技术咨询和支持@Phone13429648788 - 惜分飞 Solaris上使用DTrace进行动态跟踪 老熊的三分地-Oracle及数 ...

  9. jupyter巨好玩-使用jupyter结合VScode写博客

    打开jupyter-ipython 其实人家就叫jupyter了,后面咱可能就少提ipython了. # 打开命令行,让我们输入 jupyter notebook 当然,这个前提是你已经安装了jupy ...

随机推荐

  1. Python 中的深拷贝和浅拷贝

    一.浅拷贝python中 对象赋值时 默认是浅拷贝,满足如下规律:1. 对于 不可变对象(字符串,元组 等),赋值 实际上是创建一个新的对象:例如: >>> person=['nam ...

  2. MySQL--Percona-XtraDB-Cluster使用xtrabackup来添加节点

    虽然PXC支持在线增加群集节点,但是目前尚未解决wsrep_sst_method=xtrabackup 或wsrep_sst_method=mysqldump时报错的问题,因此尝试手动完成xtraba ...

  3. 58VIP账号发贴器

    因公司有招聘大量普工需求,需要大量简历资源,直接从58买一份简历动辄几块到几十块,如果做精准少则1块以上的点击.而且收到的简历不太精准,应公司需求写了一款自动发贴器.完全模拟人工发贴,经过一个月的测试 ...

  4. iis支持asp.net4.0的注册命令使用方法

    32位的Windows: 1. 运行->cmd 2. cd C:\Windows\Microsoft.NET\Framework\v4.0.30319 3. aspnet_regiis.exe ...

  5. ffplay源码分析5-图像格式转换

    本文为作者原创,转载请注明出处:https://www.cnblogs.com/leisure_chn/p/10311376.html ffplay是FFmpeg工程自带的简单播放器,使用FFmpeg ...

  6. MariaDB 数据库索引详解(9)

    MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可MariaDB的目的是完全兼容MySQL,包括API和命令行,MySQL由于现在闭源了,而能轻松成为MySQ ...

  7. Android实战源码--围住神经猫

    最终效果: AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manif ...

  8. linux源码安装的步骤

    源码安装的过程中多多少少会遇到问题,在此仅简述一下安装的步骤,具体安装的过程中遇到的问题,具体解决. 安装步骤: 1.获取源码 name.gz 2.解包 tar -xvf name.gz (cd到包解 ...

  9. 在vue里面使用iVew框架

    iVew框架的文档   https://www.iviewui.com/docs/guide/install 这里使用的是 npm 来安装,在项目下执行下面命令npm install iview -- ...

  10. vs2017配置pthread.h的方法

    一.背景(以下为走不通的配置方法!) 笔者最开始配置pthread.h,采用的是vs自动安装的方法,如图所示. 点击完“管理NuGet程序包”之后,弹出一个页面,如下,在“浏览”中输入pthread. ...