(转载)UIKIt力学教程
转载自:http://www.cocoachina.com/ios/20131226/7614.html
- UIView* square = [[UIView alloc] initWithFrame:
- CGRectMake(100, 100, 100, 100)];
- square.backgroundColor = [UIColor grayColor];
- [self.view addSubview:square];
- UIDynamicAnimator* _animator;
- UIGravityBehavior* _gravity;
- _animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
- _gravity = [[UIGravityBehavior alloc] initWithItems:@[square]];
- [_animator addBehavior:_gravity];
- UICollisionBehavior* _collision;
- 在 viewDidLoad 末尾加入以下代码:
- _collision = [[UICollisionBehavior alloc]
- initWithItems:@[square]];
- _collision.translatesReferenceBoundsIntoBoundary = YES;
- [_animator addBehavior:_collision];
- UIView* barrier = [[UIView alloc] initWithFrame:CGRectMake(0, 300, 130, 20)];
- barrier.backgroundColor = [UIColor redColor];
- [self.view addSubview:barrier];
- _collision = [[UICollisionBehavior alloc] initWithItems:@[square, barrier]];
- _collision = [[UICollisionBehavior alloc] initWithItems:@[square]];
- // add a boundary that coincides with the top edge
- CGPoint rightEdge = CGPointMake(barrier.frame.origin.x +
- barrier.frame.size.width, barrier.frame.origin.y);
- [_collision addBoundaryWithIdentifier:@"barrier"
- fromPoint:barrier.frame.origin
- toPoint:rightEdge];
- _collision.action = ^{
- NSLog(@"%@, %@",
- NSStringFromCGAffineTransform(square.transform),
- NSStringFromCGPoint(square.center));
- };
- 2013-07-26 08:21:58.698 DynamicsPlayground[17719:a0b] [1, 0, 0, 1, 0, 0], {150, 236}
- 2013-07-26 08:21:58.715 DynamicsPlayground[17719:a0b] [1, 0, 0, 1, 0, 0], {150, 243}
- 2013-07-26 08:21:58.732 DynamicsPlayground[17719:a0b] [1, 0, 0, 1, 0, 0], {150, 250}
- 2013-07-26 08:21:59.182 DynamicsPlayground[17719:a0b] [0.10679234, 0.99428135, -0.99428135, 0.10679234, 0, 0], {198, 325}
- 2013-07-26 08:21:59.198 DynamicsPlayground[17719:a0b] [0.051373702, 0.99867952, -0.99867952, 0.051373702, 0, 0], {199, 331}
- 2013-07-26 08:21:59.215 DynamicsPlayground[17719:a0b] [-0.0040036771, 0.99999201, -0.99999201, -0.0040036771, 0, 0], {201, 338}
- @protocol UIDynamicItem
- @property (nonatomic, readwrite) CGPoint center;
- @property (nonatomic, readonly) CGRect bounds;
- @property (nonatomic, readwrite) CGAffineTransform transform;
- @end
- @interface ViewController ()
- @end
- _collision.collisionDelegate = self;
- - (void)collisionBehavior:(UICollisionBehavior *)behavior beganContactForItem:(id)item
- withBoundaryIdentifier:(id)identifier atPoint:(CGPoint)p {
- NSLog(@"Boundary contact occurred - %@", identifier);
- }
- 2013-07-26 08:44:37.473 DynamicsPlayground[18104:a0b] Boundary contact occurred - barrier
- 2013-07-26 08:44:37.689 DynamicsPlayground[18104:a0b] Boundary contact occurred - barrier
- 2013-07-26 08:44:38.256 DynamicsPlayground[18104:a0b] Boundary contact occurred - (null)
- 2013-07-26 08:44:38.372 DynamicsPlayground[18104:a0b] Boundary contact occurred - (null)
- 2013-07-26 08:44:38.455 DynamicsPlayground[18104:a0b] Boundary contact occurred - (null)
- 2013-07-26 08:44:38.489 DynamicsPlayground[18104:a0b] Boundary contact occurred - (null)
- 2013-07-26 08:44:38.540 DynamicsPlayground[18104:a0b] Boundary contact occurred - (null)
- UIView* view = (UIView*)item;
- view.backgroundColor = [UIColor yellowColor];
- [UIView animateWithDuration:0.3 animations:^{
- view.backgroundColor = [UIColor grayColor];
- }];
- UIDynamicItemBehavior* itemBehaviour = [[UIDynamicItemBehavior alloc] initWithItems:@[square]];
- itemBehaviour.elasticity = 0.6;
- [_animator addBehavior:itemBehaviour];
- BOOL _firstContact;
- if (!_firstContact)
- {
- _firstContact = YES;
- UIView* square = [[UIView alloc] initWithFrame:CGRectMake(30, 0, 100, 100)];
- square.backgroundColor = [UIColor grayColor];
- [self.view addSubview:square];
- [_collision addItem:square];
- [_gravity addItem:square];
- UIAttachmentBehavior* attach = [[UIAttachmentBehavior alloc] initWithItem:view
- attachedToItem:square];
- [_animator addBehavior:attach];
- }
转载于:https://www.cnblogs.com/lizhitai/p/4597080.html
(转载)UIKIt力学教程相关推荐
- UIKit 力学教程
你可能已经注意到 iOS 7 中似乎有一些自相矛盾的地方,苹果在建议放弃真实世界的隐喻和拟物化同时,又鼓励创造体验真实的用户界面. 在实践中这意味着什么呢?iOS 7 的设计目标是鼓励创造能像真实的物 ...
- [转载]批处理入门教程
[转载]批处理入门教程 写这篇教程的目的,是让每一个看过这些文字的朋友记住一句话:如果爱可以让事情变的更简单,那么就让它简单吧!看这篇教程的方法 脚本之家补充说明:批处理相对来说是比较简单的语言,大家 ...
- [转载]windbg简明教程
[转载]windbg简明教程 文章作者:Sucsor on 2006.06.11 Windbg是 Microsoft公 司免费调试器调试集合中的GUI的调试器,支持Source和Assembly两种模 ...
- [转载]VBS入门教程 VBS基础教程
[转载]VBS入门教程 VBS基础教程(收藏) VBS基础教程 VBS(VBScript的进一步简写)是基于Visual Basic的脚本语言. Microsoft Visual Basic是微软公司 ...
- Advanced Mechanics in CG Animation CG动画高级力学教程 Lynda课程中文字幕
Advanced Mechanics in CG Animation 中文字幕 CG动画高级力学教程 中文字幕Advanced Mechanics in CG Animation 力学 - 动画的支柱 ...
- 转载 树莓派vnc 教程
VNC远程连接树莓派完全教程 爱上半导体 18-07-1712:48 树莓派3B.3B+自带了VNC,我们不需要在用指令给树莓派安装 为了能在电脑上使用VNC的方式远程树莓派,我真是操碎了心,断断续续 ...
- [转载]SVN使用教程
SVN简介: 为什么要使用SVN? 程序员在编写程序的过程中,每个程序员都会生成很多不同的版本,这就需要程序员有效的管理代码,在需要的时候可以迅速,准确取出相应的版本. Subversion是什么? ...
- 转载:ubuntu教程
Ubuntu完全教程,让你成为Ubuntu高手! Ubuntu的发音 Ubuntu,源于非洲祖鲁人和科萨人的语言,发作 oo-boon-too 的音.了解发音是有意义的,您不是第一个为此困惑的人,当然 ...
- [转载]NetBox使用教程!
原文地址:NetBox使用教程! 作者:海阔天空 NetBox使用教程!(很全) 1. 网易征兵 2. 现在什么网站能赚钱? 3. NetBox使用教程! 4. ...
最新文章
- Netty深入浅出(一)入门
- 新鲜出炉!20款好看的英文字体下载
- 放弃中国国籍 却赚着中国人的钱
- TabControl控件用法图解
- Python练习之 对文件进行创建,然后重命名文件最近进行文件删除
- 用计算机解决问题 评课稿,总结反思:二年级数学lbrack;解决问题rsqb;评课稿
- 性能测试流程与性能测试分析和问题定位分享
- 数据结构和算法(十三)排序算法
- 关闭笔记本电脑计算机键盘,笔记本小键盘怎么关闭,教您怎么关闭笔记本小键盘...
- 浙江大学黄杨思博计算机学院,浙江大学2010-2011学年大学生学科竞赛获奖名单
- Telos 首份年报(中译版-下)
- 曾经以为老去是很遥远的事情
- 关于精益创业的方法论,看完这些就掌握了大半!
- REST ful风格总结(在逍遥子的基础上~只供自己简单总结,详情请看原文)
- 职场菜鸟捕食指北【初入职场篇】
- 【Multisim仿真】差分比例放大电路
- LinkedList真的比ArrayList增删快吗?为什么?
- 湘潭大学计算机组成原理试卷,湘潭大学 计算机组成与原理 控制器实验 实验报告...
- Android自动化测试工具调研
- Color Constancy 色彩恒常性(1)White Patch Retinex