UIDynamic的基本使用
2014-04-21 15:03
197 查看
一.使用步骤
1.创建仿真者
UIDynamicAnimator *animaytor = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];//后面的参数是:参照哪个View
2.添加要仿真的动作或者行为
UIGravityBehavior *gravity = [[UIGravityBehavior alloc] initWithItems:@[redView,blueView]];
//添加碰撞检测行为
UICollisionBehavior *collision = [[UICollisionBehavior alloc] initWithItems:@[redView,blueView]];
3.将动作添加到仿真者中
[animaytor addBehavior:collision];
collision.translatesReferenceBoundsIntoBoundary = YES;
将动作添加到仿真者中
[animaytor addBehavior:gravity];
_animator = animaytor;//必须定义一个成员变量保存住仿真者,否则出了这个方法仿真者就不存在了
============================================================================
1.添加吸附动作 UISnapBehavior ------->吸附动作必须清除仿真者之前的行为
UISnapBehavior *snap = [[UISnapBehavior alloc] initWithItem:self.box snapToPoint:location];//location是目标点
[self.animator addBehavior:snap];
2.推动作 UIPushBehavior
1>推行为必须设置3个属性 --->偏移量 //计算偏移量CGPoint offset = CGPointMake(_FristPoint.x - endPoint.x, _FristPoint.y - endPoint.y);
1)距离 也就是推行为的距离 --->按下屏幕的x,y -离开屏幕的x,y是偏移量,然后再用偏移量的(x*x+y*y)在开方,就是要求的距离,具体参考三角形求斜边公式
2)角度 ----->CGFloat angle = atan2f(offSet.y, offSet.x)
3) _push.active = YES;
3.刚性动作
1> 刚性行为初始化的时候需要指定2个点
1)定位点
2)锚点
4.弹性刚性行为----->和刚性动作大部分一样
多两个属性要设置
1)damping 振幅
2)frequency 频率
5.碰撞检测 ---->UICollisionBehavior
UICollisionBehavior *collision = [[UICollisionBehavior alloc] initWithItems:@[blueView]];
Boundary是即参与碰撞,又不会发生位移的静态物体的边界
[collision addBoundaryWithIdentifier:@"lalala" fromPoint:redView.frame.origin toPoint:CGPointMake(toX, toY)];
#pragma mark - 碰撞的代理方法
- (void)collisionBehavior:(UICollisionBehavior *)behavior beganContactForItem:(id<UIDynamicItem>)item withBoundaryIdentifier:(id<NSCopying>)identifier atPoint:(CGPoint)p
1.创建仿真者
UIDynamicAnimator *animaytor = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];//后面的参数是:参照哪个View
2.添加要仿真的动作或者行为
UIGravityBehavior *gravity = [[UIGravityBehavior alloc] initWithItems:@[redView,blueView]];
//添加碰撞检测行为
UICollisionBehavior *collision = [[UICollisionBehavior alloc] initWithItems:@[redView,blueView]];
3.将动作添加到仿真者中
[animaytor addBehavior:collision];
collision.translatesReferenceBoundsIntoBoundary = YES;
将动作添加到仿真者中
[animaytor addBehavior:gravity];
_animator = animaytor;//必须定义一个成员变量保存住仿真者,否则出了这个方法仿真者就不存在了
============================================================================
1.添加吸附动作 UISnapBehavior ------->吸附动作必须清除仿真者之前的行为
UISnapBehavior *snap = [[UISnapBehavior alloc] initWithItem:self.box snapToPoint:location];//location是目标点
[self.animator addBehavior:snap];
2.推动作 UIPushBehavior
1>推行为必须设置3个属性 --->偏移量 //计算偏移量CGPoint offset = CGPointMake(_FristPoint.x - endPoint.x, _FristPoint.y - endPoint.y);
1)距离 也就是推行为的距离 --->按下屏幕的x,y -离开屏幕的x,y是偏移量,然后再用偏移量的(x*x+y*y)在开方,就是要求的距离,具体参考三角形求斜边公式
2)角度 ----->CGFloat angle = atan2f(offSet.y, offSet.x)
3) _push.active = YES;
3.刚性动作
1> 刚性行为初始化的时候需要指定2个点
1)定位点
2)锚点
4.弹性刚性行为----->和刚性动作大部分一样
多两个属性要设置
1)damping 振幅
2)frequency 频率
5.碰撞检测 ---->UICollisionBehavior
UICollisionBehavior *collision = [[UICollisionBehavior alloc] initWithItems:@[blueView]];
Boundary是即参与碰撞,又不会发生位移的静态物体的边界
[collision addBoundaryWithIdentifier:@"lalala" fromPoint:redView.frame.origin toPoint:CGPointMake(toX, toY)];
#pragma mark - 碰撞的代理方法
- (void)collisionBehavior:(UICollisionBehavior *)behavior beganContactForItem:(id<UIDynamicItem>)item withBoundaryIdentifier:(id<NSCopying>)identifier atPoint:(CGPoint)p
相关文章推荐
- UIDynamic介绍
- UIDynamic-物理引擎
- UIDynamic介绍
- OCiOS开发:UIKit 力学(UIDynamics)(二)
- OCiOS开发:UIKit 力学(UIDynamics)(一)
- 跟着斯坦福白胡子老头学UIDynamic动画的技巧
- UIKit 力学教程
- UIDynamic 物理动效
- iOS-UIDynamic物理仿真-重力、碰撞
- UIDynamic—UIKit 动力学
- UITableView的简单使用
- 使用UIScrollView 实现分页功能
- UIScrollView的简单使用
- UIView的transform属性值详解
- UIView的常用属性
- Android 应用程序窗体显示状态操作(requestWindowFeature()的应用)
- MFC 自定义非窗口类控件中实现 ON_COMMAND 和 ON_UPDATE_COMMAND_UI
- 转: requirejs压缩打包r.js使用示例 2 (~~很详细的教程)
- iOS摄像头和相册-UIImagePickerController-浅析(转)
- 转:requirejs打包压缩r.js使用示例