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 ...
随机推荐
- hdu 1.3.2 Moving Tables
这道题比较简单,就是用数组存取其路径.如101和102是对门,其过道号可以记为51. 1和2之间的为1. 今早突然收到操作系统停课的通知,哈哈 回来就做一下水题,开心 #include<cst ...
- springmvc配置文件web.xml详解各方总结。
Spring分为多个文件进行分别的配置,其中在servlet-name中如果没有指定init-param属性,那么系统自动寻找的spring配置文件为[servlet-name]-servlet.xm ...
- MySQL--REPALCE INTO操作
REPLACE INTO语法是MySQL数据库独特的扩展语法,可以提供“不存在即插入,存在即更新”的操作,MySQL官方文档解析其算法为: 1.尝试进行INSER 操作 2.如果INSERT 失败,则 ...
- 输出的数据格式是如何决定的-------Asp.net WebAPI学习笔记(二)
在上一篇文章<路由其实也可以很简单>,我们解决了路由问题,这篇文章,我们来研究剩下的另一个问题,为何我们的方法返回的是一个列表,输出到客户端的时候,变成json呢,大家应该还记得我们上一篇 ...
- DataFrame 操作
# 删除td数据框中的 指定列 td.drop(columns=['ship-city'],axis=1,inplace=True) #删除指定列 并且修改掉原始数据 # 删除td数据框中的 最后一列 ...
- Bootstrap框架下实现图片切换
准备图片,把相关记录添加至数据库表中: 创建一个存储过程,获取所有记录: 在ASP.NET MVC专案中,部署Bootstrap环境...... 然后创建一个model: using System; ...
- [leetcode.com]算法题目 - Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- Vue过渡动画—Vue学习笔记
要求:要通过Vue使用过渡动画我们要把需要过度的元素放在<transition name='变量名'></transition>中. 原理:通过在特定的时刻增加/移除样式实现. ...
- Docker - 基础讲义
Docker Docker - 官网 Docker - Hub GitHub - Docker dockerinfo Docker中文社区 Docker入门教程 Docker从入门到实践 虚拟化技术 ...
- POJ 2704
#include <iostream> #include <string> #define LL long long #define MAXN 100 using namesp ...