#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 操作mysql数据库之模拟购物系统登录及购物

    python 操作mysql数据库之模拟购物系统登录及购物,功能包含普通用户.管理员登录,查看商品.购买商品.添加商品,用户充值等. mysql 数据库shop 表结构创建如下: create TAB ...

  2. 使用 xUnit 编写 ASP.NET Core WebAPI单元测试

    本文使用xUnit对ASP.NET Core WebAPI做单元测试,使用HttpClient的同步和异步请求,下面详细介绍xUnit的使用过程: 一.创建示例项目 模板为我们自动创建了一个Value ...

  3. 由VC2010与VC2017数据结构差异造成的程序错误

    内容:VC2010和VC2017的标准库中,string(或wstring)的数据结构和操作有所不同,所以在将这两种数据作为参数在两个系统产生的函数中传递时会出现乱码(string和wstring在2 ...

  4. 背水一战 Windows 10 (56) - 控件(集合类): ListViewBase - 基础知识, 拖动项

    [源码下载] 背水一战 Windows 10 (56) - 控件(集合类): ListViewBase - 基础知识, 拖动项 作者:webabcd 介绍背水一战 Windows 10 之 控件(集合 ...

  5. 【BZOJ2882】 工艺(SAM)

    传送门 BZOJCH 洛谷 Solution 这个东西要求的不就是最小表示法吗? 把原串复制一遍然后都加到后缀自动机里面去. 用个map跑一下,这样子可以保证每一次选的是最小字典序的. 然后跑\(n\ ...

  6. OSLab多进程

    日期:2019/3/23 内容:Linux下与多进程相关的函数.     进程基本知识 定义 应用程序关于某数据集合上的一次运行活动. 特点 ·操作系统进行资源分配和调度的基本单位 ·进程是程序的一次 ...

  7. [BZOJ2738]矩阵乘法(整体二分+二维树状数组)

    整体二分+二维树状数组. 好题啊!写了一个来小时. 一看这道题,主席树不会搞,只能用离线的做法了. 整体二分真是个好东西,啥都可以搞,尤其是区间第 \(k\) 大这种东西. 我们二分答案,然后用二维树 ...

  8. jzoj4235 序列

    取前50個數暴力即可 #include<bits/stdc++.h> using namespace std; int n,m,a[100010],q[5]; int main(){ sc ...

  9. DevOps - CI - Sonar

    Sonar 官方信息 https://www.sonarqube.org/ https://www.sonarqube.org/downloads/ https://docs.sonarqube.or ...

  10. Nginx安装使用及与tomcat实现负载均衡

    1. 背景 基于nginx强大的功能,实现一种负载均衡,或是不停机更新程序等.nginx相比大家基本上都知道是什么来头了,具体的文章大家可以去搜索相关文章学习阅读,或是可以查看Nginx中文文档和Ng ...