IOS7开发~UIKit Dynamics

UIKit Dynamics的中文名称:有叫UIKit动力,也有叫UIKit动力模型和UIKit动态或者动态UI,叫什么名不要紧,理解就含义就可以了。

什么是UIKit Dynamics ?

UIKit动力提供了一个模拟真实世界中力学相关的动画和交互系统。比如重力、碰撞和吸附等。UIKit动力具有可组合、可重用和声明式的特点。我的理解就是把游戏开发中的物理引擎的搬过来了。

 

首先简单看几点基础知识:

1、UIDynamicAnimator:

a、

A dynamic animator provides physics-related capabilities and animations for its dynamic items, and providesthe context for those animations. It does this by intermediating between the underlying iOS physics engineand dynamic items, via behavior objects you add to the animator. 

UIDynamicAnimator类的作用是起到衔接动力项和view,很重要。

 

b、

可以有这些作用:(当然,英文不用都理解,明白大致意思就可以,后面看代码就明白了)

All types of dynamic animators share the following characteristics:

Each dynamic animator is independent of other dynamic animators you create

You can associate a given dynamic item with multiple behaviors, provided those behaviors belong to thesame animator

An animator automatically pauses when all its items are at rest, and automatically resumes when a behaviorparameter changes or a behavior or item is added or removed 


c、

初始化方法:

– initWithReferenceView:
Initializes a dynamic animator with a specified view as its reference view. 

初始化方法里关联view!

d、

UIDynamicAnimator在view中实现的时候,也有其代理方法:

dynamicAnimatorDidPause:   动力项在view中被Pause的时候时候回调此方法

dynamicAnimatorWillResume:  动力项在view中Resume的时候时候回调此方法


2、一些动力项(都是模拟真实物体在现实中的行为)

UIAttachmentBehavior       吸附
UICollisionBehavior            碰撞
UIDynamicItemBehavior    活力(类似真实物体,有活力,更逼真)
UIGravityBehavior              重力(物体受重力影响自由下落)
UIPushBehavior                 推动
UISnapBehavior objects    仓促


下看就去看代码吧:官网demo(http://pan.baidu.com/share/link?shareid=1092885049&uk=3674861929

UIDynamicAnimator_Class 文档下载直通车:http://pan.baidu.com/share/link?shareid=1108425560&uk=3674861929

更多内容请查看官网:https://developer.apple.com/wwdc/schedule/

这个爱学习的人的博客也很有用:http://www.cocoachina.com/newbie/basic/2013/0612/6393.html

注意:

1、如果看代码,或者自己建立项目的时候,出现IOS7的build错误了,那就看看这里吧 http://blog.csdn.net/zfpp25_/article/details/9106573

2、看代码时,会遇到 anchorPoint (锚点)这个游戏中常用的概念,不明白不要紧,看这里 http://blog.csdn.net/zfpp25_/article/details/8641651

虽然官网的例子也有问题,不过新东西,代码太少,将就看吧,由于工作忙,所以没那么多空闲时间,就到这里吧。祝学习快乐。

原文地址:https://www.cnblogs.com/yingkong1987/p/3343921.html