ios动力特效,最重要的一点 属性保持(写了动力特效但是没效果的原因就在这里)
Posted 今天就是明天
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ios动力特效,最重要的一点 属性保持(写了动力特效但是没效果的原因就在这里)相关的知识,希望对你有一定的参考价值。
@property (nonatomic, strong) UIDynamicItemBehavior *square1PropertiesBehavior;
@property (nonatomic, strong) UIDynamicItemBehavior *square2PropertiesBehavior;
@property (nonatomic, strong) UIDynamicAnimator *animator;
@property(nonatomic,strong)UIDynamicAnimator*dy;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIView * apple = [[UIView alloc] initWithFrame:CGRectMake(40,40, 40, 40)];
apple.backgroundColor = [UIColor redColor];
[self.view addSubview:apple];
UIDynamicAnimator *animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
UIGravityBehavior *gravityBeahvior = [[UIGravityBehavior alloc] initWithItems:@[apple]];
UICollisionBehavior *collisionBehavior = [[UICollisionBehavior alloc] initWithItems:@[apple]];
UIDynamicItemBehavior*behavior = [[UIDynamicItemBehavior alloc] initWithItems:@[apple]];
//behavior.elasticity = ;
collisionBehavior.translatesReferenceBoundsIntoBoundary = YES;
[animator addBehavior:gravityBeahvior];
[animator addBehavior:collisionBehavior];
[animator addBehavior:behavior];
self.dy = animator; //属性保持才能有动画效果
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
以上是关于ios动力特效,最重要的一点 属性保持(写了动力特效但是没效果的原因就在这里)的主要内容,如果未能解决你的问题,请参考以下文章