您的位置:首页 > 产品设计 > UI/UE

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];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: