iOS7中UIKit支持的动力行为之UIAttachmentBehavior
来源:互联网 发布:台北北投温泉攻略 知乎 编辑:程序博客网 时间:2024/04/19 17:13
来源:http://www.2cto.com/kf/201401/275889.html
动力item可以是任何符合UIDynamicItem协议的iOS对象或者自定义对象,UIView和UICollectionViewLayoutAttributes类在iOS7.0才开始实现这个协议。你可以用一个自定义对象作为动力item,这个动力item能够对旋转或位置的改变作出反应,这些都是由一个动力动画制作者(UIDynamicAnimator类的实例)来计算的。
当一个动力item移动的时候,通过跟踪手势或其他输入方式,任何被吸附的动力item都要移动。如果可能,还可以给这些被吸附的动力item设置另外的动力参数和边界。你可以使用length、damping和frequency属性设置吸附行为。
若要实现动力item的吸附行为,要执行以下两个步骤: 1.用一个或者两个item初始化吸附行为, 初始化方法是initWithItem:... 2.通过使用addBehavior:method将它添加到动画中去 吸附行为还与坐标系统有关,你可以和行为一起用的动力items的类型,取决于你怎么初始化相关的动画。
你也能在自定义的复合行为中包含吸附行为,这个复合行为要以UIDynamicBehavior对象开始,用addChildBehavior:method添加吸附行为。如果你想吸附行为在每一步动力动画上都很流畅的话,就要实现继承的action方法。
方法
初始化和管理吸附行为
参数:items
– initWithItem:attachedToAnchor:
– initWithItem:attachedToItem:
– initWithItem:offsetFromCenter:attachedToAnchor:
- – initWithItem:offsetFromCenter:attachedToItem:offsetFromCenter:
配置吸附行为anchorPoint
propertyattachedBehaviorType
propertydamping
propertyfrequency
propertylength
property
属性
anchorPoint: UIAttachmentBehaviorTypeAnchor类型的依赖行为的锚点,锚点与行为相关的动力动画的坐标系统有关。 @property(readwrite, nonatomic) CGPoint anchorPoint
attachedBehaviorType: 吸附行为的类型 @property(readonly, nonatomic) UIAttachmentBehaviorType attachedBehaviorType damping: 描述吸附行为减弱的阻力大小 @property(readwrite, nonatomic) CGFloat damping
frequency: 吸附行为震荡的频率 @property(readwrite, nonatomic) CGFloat frequency
items: 与吸附行为相连的动态项目,当吸附行为类型是UIAttachmentBehaviorTypeItems时有2个元素,当吸附行为类型是
UIAttachmentBehaviorTypeAnchor
时只有一个元素。@property(nonatomic, readonly, copy) NSArray *items
length:
吸附行为中的两个吸附点之间的距离,通常用这个属性来调整吸附的长度,可以创建吸附行为之后调用。系统基于你创建吸附行为的方法来自动初始化这个长度 @property(readwrite, nonatomic) CGFloat length
方法举例
initWithItem:attachedToAnchor: 初始化连接动力item的中心和锚点的吸附行为 - (instancetype)initWithItem:(id)item attachedToAnchor:(CGPoint)point
参数:item是你要应用吸附行为的动力项,point是吸附行为的锚点,与跟行为相关的动态动画所在在系统坐标有关。 返回:初始化的attachment behavior,如果初始化过程出错将会返回nil。 该初始化方法的吸附行为的类型是UIAttachmentBehaviorTypeAnchorinitWithItem:attachedToItem:
初始化连接两个动力项中心的吸附行为
- (instancetype)initWithItem:(id)item1 attachedToItem:(id)item2
参数:item1第一个被吸附行为连接的动力项,item2第二个被吸附行为连接的动力项 返回:初始化的attachment behavior,如果初始化过程出错将会返回nil。 该初始化方法的吸附行为的类型是UIAttachmentBehaviorTypeItems
initWithItem:offsetFromCenter:attachedToAnchor:
初始化连接动力项中某一点和锚点的吸附行为
- (instancetype)initWithItem:(id)item offsetFromCenter:(UIOffset)p1 attachedToAnchor:(CGPoint)point
参数:item要应用吸附行为的动力项,p1相对于item中心的偏移,point是吸附行为的锚点,与跟行为相关的动力动画所在在系统坐标有关。 返回:初始化的attachment behavior,如果初始化过程出错将会返回nil。 该初始化方法的吸附行为的类型是UIAttachmentBehaviorTypeAnchorinitWithItem:offsetFromCenter:attachedToItem:offsetFromCenter:
初始化连接一个动力item中某一点和另一个动力item中某一点的吸附行为
- (instancetype)initWithItem:(id)item1 offsetFromCenter:(UIOffset)p1 attachedToItem:(id)item2 offsetFromCenter:(UIOffset)p2
参数:item1第一个被吸附行为连接的动力项,p1相对于item1中心的偏移,item2第二个被吸附行为连接的动力项,p2相对于item2中心的偏移 返回:返回:初始化的attachment behavior,如果初始化过程出错将会返回nil。 这是为UIAttachmentBehavior类指定的初始化程序。
常量UIAttachmentBehaviorType
吸附行为的类型,说明吸附到的是什么样子的动力项。UIAttachmentBehaviorTypeItems:表示连接两个item的吸附行为1234typedef
enum
{
UIAttachmentBehaviorTypeItems,
UIAttachmentBehaviorTypeAnchor
} UIAttachmentBehaviorType;
UIAttachmentBehaviorTypeAnchor:表示连接一个item与锚点的吸附行为
0 0
- iOS7中UIKit支持的动力行为之UIAttachmentBehavior
- iOS7中UIKit支持的动力行为之UIAttachmentBehavior
- iOS7中UIKit支持的动力行为之UIAttachmentBehavior
- 如何在iOS7中使用UIKit动力之UICollisionBehavior
- iOS7新特征汇总[05]初窥UIKit动力(UIKit Dynamics)
- iOS7新特征汇总[05]初窥UIKit动力(UIKit Dynamics)
- iOS7新特征汇总[05]初窥UIKit动力(UIKit Dynamics)
- iOS7新特征汇总[05]初窥UIKit动力(UIKit Dynamics)
- iOS7新特征汇总[05]初窥UIKit动力(UIKit Dynamics)
- iOS7新特征汇总[05]初窥UIKit动力(UIKit Dynamics)
- ios7新特征,UIKit Dynamics(UIKit动力模型)
- UIKit 框架中Dynamics (动力:重力,推力,撞击)
- ios UIKit动力
- UIKit Dynamic 动力特效----吸附
- UIKit Dynamics动力系统入门
- IOS7开发~UIKit Dynamics
- IOS7 UIKit Dynamics Tutorial
- iOS7 UIKit Dynamics
- 常见浏览器HACK技巧总结
- 线程面试题之一:父子线程的同步
- 给图片添加超链接
- hive学习 hql操作
- LCA题目总结
- iOS7中UIKit支持的动力行为之UIAttachmentBehavior
- HDU 3061 Battle 最大权闭合图
- Android项目打包开启proguard的混淆优化带来的有关问题
- 我是佛欧威尔丰盛的了感觉的发生第三个富二代劫匪开始得
- xUtils 简介
- text-shadow
- UVA 10214 - Trees in a Wood.
- PHP 第七章
- chrome找不到模拟移动端