[iOS开发] UIKit Dynamics
2014-01-28 10:28
316 查看
关于 UIKit Dynamics 的中译名,我与许多开发者有过讨论,有动力、动力模型、动态等译法。但我认为译为力学更为贴切,希望文中出现的力学知识能让你认同我的看法。
http://www.cocoachina.com/applenews/devnews/2013/1226/7614.html
简单的重力影响view,使之垂直降落,在触底后有一个轻微的弹起,然后再落下
#import "MainViewController.h" @interface MainViewController () @property(nonatomic,retain)UIDynamicAnimator *animator; @property(nonatomic,retain)UIGravityBehavior *gravity; @property(nonatomic,retain)UICollisionBehavior *collision; @end @implementation MainViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. UIView *square = [[UIView alloc] initWithFrame:CGRectMake(30, 30, 100, 100)]; square.backgroundColor = [UIColor redColor]; [self.view addSubview:square]; //会出现重力现象,上面创建的正方形会掉落下去 //UIDynamicAnimator 是 UIKit 物理引擎。这个类会记录你添加到引擎中的各种行为(比如重力),并且提供全局上下文。当你创建动画实例时,需要传入一个参考视图用于定义坐标系。 //UIGravityBehavior 把重力的行为抽象成模型,并且对一个或多个元素施加作用力,让你可以建立物理交互模型。当你创建一个行为实例的时候,你需要把它关联到一组元素上,一般是一组视图。这样你就能选择受该行为影响的元素,在这个例子中就是指受重力影响的元素 _animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view]; _gravity = [[UIGravityBehavior alloc] initWithItems:@[square]]; [_animator addBehavior:_gravity]; _collision = [[UICollisionBehavior alloc] initWithItems:@[square]]; _collision.translatesReferenceBoundsIntoBoundary = YES;//让UIDynamicAnimator以视图的bounds为边界 [_animator addBehavior:_collision]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
相关文章推荐
- iOS开发UIKit动力学——UIKit Dynamics
- 【iOS开发】UIKit Dynamics
- 【iOS开发】UIKit Dynamics
- iOS开发资源:FlatUIKit、MMDrawerController以及MZDayPicker等
- 实战iOS 9:剖析UIKit Dynamics的改进
- IOS7开发~UIKit Dynamics
- iOS开发图片美白处理,图像处理,,磨皮,马赛克基于UIKit下自写算法
- iOS开发UIKit框架-可视化编程-XIB
- iOS开发UIKit框架-可视化编程-XIB
- 芒果iOS开发之Xcode8控制台输出警告:subsystem: com.apple.UIKit, category: HIDEventFiltered, enable_level: 0
- IOS开发之通过官网系统学习UIKit
- iOS开发之Xcode8控制台输出警告:subsystem: com.apple.UIKit, category: HIDEventFiltered, enable_level: 0
- iOS开发资源:FlatUIKit、MMDrawerController以及MZDayPicker等
- iOS开发之UIKit类继承图
- OCiOS开发:UIKit 力学(UIDynamics)(一)
- 窗口,视图,视图控制器和UIKit基础-IOS开发
- iOS 7 by tutorials 学习笔记 01 - UIKit Dynamics and Motion Effects 上
- iOS应用开发新手教程:iOS5 UIKit新特性
- iOS开发UI篇—Quartz2D(五) 图片裁剪圆形,UIKit的绘图方法,Path路径的使用
- iOS 力学动画生成器UIKit Dynamics 之碰撞效果讲解