码迷,mamicode.com
首页 > 移动开发 > 详细

ios动力特效,最重要的一点 属性保持(写了动力特效但是没效果的原因就在这里)

时间:2016-08-26 13:29:31      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:

@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动力特效,最重要的一点 属性保持(写了动力特效但是没效果的原因就在这里)

标签:

原文地址:http://www.cnblogs.com/liutaoboke/p/5809787.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!