UIDynamicItemBehavior-动画效果:增加各种物理特性
2013-12-06 17:51
411 查看
1。可给活动项指派不同的物理特性
- (instancetype)initWithItems:(NSArray *)items //初始化
2。属性
allowsRotation
resistance: 抗阻力 0~CGFLOAT_MAX ,阻碍原有所加注的行为(如本来是重力自由落体行为,则阻碍其下落,阻碍程度根据其值来决定)
friction: 磨擦力 0.0~1.0 在碰撞行为里,碰撞对象的边缘产生
elasticity:弹跳性 0.0~1.0
density:密度 0~1
e.g.
- (UIView *) newViewWithCenter:(CGPoint)paramCenter backgroundColor:(UIColor *)paramBackgroundColor{
UIView *newView = [[UIView alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 50.0f, 50.0f)];
newView.backgroundColor = paramBackgroundColor;
newView.center = paramCenter;
return newView;
}
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
UIView *topView = [self newViewWithCenter:CGPointMake(100.0f, 0.0f)
backgroundColor:[UIColor greenColor]];
UIView *bottomView = [self newViewWithCenter:CGPointMake(100.0f, 50.0f)
backgroundColor:[UIColor redColor]];
[self.view addSubview:topView];
[self.view addSubview:bottomView];
//构造动画
self.animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
//gravity
UIGravityBehavior *gravity = [[UIGravityBehavior alloc]
initWithItems:@[topView, bottomView]];
[self.animator addBehavior:gravity];
//collision
UICollisionBehavior *collision = [[UICollisionBehavior alloc]
initWithItems:@[topView, bottomView]];
collision.translatesReferenceBoundsIntoBoundary = YES;
[self.animator addBehavior:collision];
//指派不同特性值 弹性bounce
UIDynamicItemBehavior *moreElasticItem = [[UIDynamicItemBehavior alloc]
initWithItems:@[bottomView]];
moreElasticItem.elasticity = 1.0f;
UIDynamicItemBehavior *lessElasticItem = [[UIDynamicItemBehavior alloc]
initWithItems:@[topView]];
lessElasticItem.elasticity = 0.5f;
[self.animator addBehavior:moreElasticItem];
[self.animator addBehavior:lessElasticItem];
}
- (instancetype)initWithItems:(NSArray *)items //初始化
2。属性
allowsRotation
resistance: 抗阻力 0~CGFLOAT_MAX ,阻碍原有所加注的行为(如本来是重力自由落体行为,则阻碍其下落,阻碍程度根据其值来决定)
friction: 磨擦力 0.0~1.0 在碰撞行为里,碰撞对象的边缘产生
elasticity:弹跳性 0.0~1.0
density:密度 0~1
e.g.
- (UIView *) newViewWithCenter:(CGPoint)paramCenter backgroundColor:(UIColor *)paramBackgroundColor{
UIView *newView = [[UIView alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 50.0f, 50.0f)];
newView.backgroundColor = paramBackgroundColor;
newView.center = paramCenter;
return newView;
}
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
UIView *topView = [self newViewWithCenter:CGPointMake(100.0f, 0.0f)
backgroundColor:[UIColor greenColor]];
UIView *bottomView = [self newViewWithCenter:CGPointMake(100.0f, 50.0f)
backgroundColor:[UIColor redColor]];
[self.view addSubview:topView];
[self.view addSubview:bottomView];
//构造动画
self.animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
//gravity
UIGravityBehavior *gravity = [[UIGravityBehavior alloc]
initWithItems:@[topView, bottomView]];
[self.animator addBehavior:gravity];
//collision
UICollisionBehavior *collision = [[UICollisionBehavior alloc]
initWithItems:@[topView, bottomView]];
collision.translatesReferenceBoundsIntoBoundary = YES;
[self.animator addBehavior:collision];
//指派不同特性值 弹性bounce
UIDynamicItemBehavior *moreElasticItem = [[UIDynamicItemBehavior alloc]
initWithItems:@[bottomView]];
moreElasticItem.elasticity = 1.0f;
UIDynamicItemBehavior *lessElasticItem = [[UIDynamicItemBehavior alloc]
initWithItems:@[topView]];
lessElasticItem.elasticity = 0.5f;
[self.animator addBehavior:moreElasticItem];
[self.animator addBehavior:lessElasticItem];
}
相关文章推荐
- UIKit动力学-物理特性UIDynamicItemBehavior
- UIKit动力学-物理特性UIDynamicItemBehavior
- UISnapBehavior-动画效果:迅猛移动弹跳摆动
- UISnapBehavior-动画效果:迅猛移动弹跳摆动
- UIDynamicAnimator物理动画效果
- 开源项目推荐(3):Android UI Patterns 实现各种UI效果,含动画
- Android各种学习资料(Rxjava、动画、UI效果、开源库、算法、面试)资源链接
- UIAttachmentBehavior-动画效果:依附,关联
- UISnapBehavior-动画效果:迅猛移动弹跳摆动
- 动力效果 UIGravityBehavior- UICollisionBehavior- UIDynamicItemBehavior
- UI 核心动画效果设置
- IOS 动画设计(5)——用缓动函数实现物理动画效果
- 回向抖动 各种动画效果
- Android各种动画效果
- Android UI开发第十二篇——动画效果Animation
- Android 5.X 新特性详解(四)——Material Design 动画效果
- iphone开发中的各种动画效果
- Android各种动画效果ScaleAnimation,AlphaAnimation,TranslateAnimation,RotateAnimation(文章结尾有代码)
- 高仿金山《电池医生》首页一键省电UI动画效果