CATransaction(参考其他博客敲)
#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(参考其他博客敲)的更多相关文章
- 必应缤纷桌面的必应助手-软件分析和用户市场需求之-----二.体验部分 Ryan Mao (毛宇11061171) (完整版本请参考团队博客)
<必应缤纷桌面的必应助手> 2.体验部分 Ryan Mao (毛宇11061171) (完整分析报告请参考团队博客http://www.cnblogs.com/Z-XML/) 我花了2天的 ...
- 解决SkyP2M工程常见问题所参考的博客汇总
工程是基于64位的 1 Error 26 error C2491: 'HUDManager::_viewport' : definition of dllimport static data memb ...
- ADB命令详解及大全( 声明:此文是参考大佬博客所做的笔记!)
adb是什么? adb的全称为Android Debug Bridge,就是起到调试桥的作用.通过adb我们可以在Eclipse中方面通过DDMS来调试Android程序,说白了就是debug工具.a ...
- 对学长所谓“改变世界的游戏”《shield star》的运行感想-毛宇部分(完整版本请参考团队博客)
对于学长项目<shield star>的思考和看法: Ryan Mao ((毛宇) 110616-11061171 试用了一下学长黄杨等人开发的<shield star>游戏 ...
- gazebo 7.0 升级到7.15 参考他人博客
gazebo 7.0 升级到7.14 网址:https://blog.csdn.net/riancy_riancy/article/details/84568322 编译后遇到报错 ,解决问题的网址: ...
- 各大IT技术博客排行榜
cnblogs 积分排名前3000名 http://www.cnblogs.com/ 左侧有推荐博客排行 cppblog http://www.cppblog.com/AllBloggers.aspx ...
- (Beta)Let's-Beta阶段展示博客
康家华:http://www.cnblogs.com/AmazingMax/ 马阿姨:http://www.cnblogs.com/oushihuahua/ 刘彦熙:http://www.cnblog ...
- oracle 常用博客网址
使用oradebug修改数据库scn – 提供专业ORACLE技术咨询和支持@Phone13429648788 - 惜分飞 Solaris上使用DTrace进行动态跟踪 老熊的三分地-Oracle及数 ...
- jupyter巨好玩-使用jupyter结合VScode写博客
打开jupyter-ipython 其实人家就叫jupyter了,后面咱可能就少提ipython了. # 打开命令行,让我们输入 jupyter notebook 当然,这个前提是你已经安装了jupy ...
随机推荐
- Tomcat数据源配置方法总结
最近接触的数据表管理项目,涉及到了数据源配置,所以整理了一下配置方法: JNDI数据源统一都是在Tomcat下server.xml中配置的,根据应用范围的差别又分为一下几种方式: 第一种:配置单个应用 ...
- Android-AndroidStudio-AVD启动不了-emulator: Process finished with exit code 1
注意:解决此错误目前只针对Windows系统的电脑: 1.AndroidStudio-->AVDManager(Create Virtual Device): 2.提示AVD启动不了,同时Eve ...
- (leetcode162)find peak element
1题目 A peak element is an element that is greater than its neighbors. Given an input array where num[ ...
- 什么是PAGELATCH和PAGEIOLATCH
在分析SQL server 性能的时候你可能经常看到 PAGELATCH和PAGEIOLATCH.比方说 Select * from sys.dm_os_wait_stats 的输出里面就有Latch ...
- AngularJs创建自定义Service
AngularJs可以创建自定义的service.下面的自定义service实现一个double倍数的服务: 参考下面语法: app.service('double', function () { t ...
- 【问题解决方案】Keras手写数字识别-ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接
参考:台大李宏毅老师视频课程-Keras-Demo 在载入数据阶段报错: ConnectionResetError: [WinError 10054] 远程主机强迫关闭了一个现有的连接 Google之 ...
- Android------------------系统服务调用的学习
一.ServiceManager的方法: 此方法getService,用于根据名称获取当前的IBinder的代理(并没有直接获取服务), 服务提供的功能是依靠IBinder间接调用的(返回值IBind ...
- UOJ#419. 【集训队作业2018】圆形(格林公式)
题面 传送门 题解 首先您得会用格林公式计算圆的面积并 这里只需要动态维护一下圆弧就可以了 时间复杂度\(O(n^2\log n)\) //minamoto #include<bits/stdc ...
- 文本属性和字体属性,超链接导航栏案例 background
文本属性 介绍几个常用的. 文本对齐 text-align 属性规定元素中的文本的水平对齐方式. 属性值:none | center | left | right | justify 文本颜色 col ...
- Windows + VS2013 + Dlib
Dlib是一个机器学习的C++库,包含了许多机器学习常用的算法, 而且文档和例子都非常详细. 安装有点类似于opencv,这里我从官网下载dlib-18.17到D盘 1. cmake转VS工程 这里使 ...