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

UISnapBehavior-动画效果:迅猛移动弹跳摆动

2015-09-06 10:31 369 查看
1。与之前的UIPushBehavior不同,之前的Push只是中规中矩的移动

而这个SnapBehavior带来的移动视觉效果更强烈

- (instancetype)initWithItem:(id<UIDynamicItem>)item snapToPoint:(CGPoint)point //初始化,每一个snapBehavior只能关联一个对象

damping //CGFloat ,迅猛度,弹性[0,1]默认0.5

e.g.

- (void)viewDidAppear:(BOOL)animated{

[super viewDidAppear:animated];

[self createGestureRecognizer];

[self createSmallSquareView];

[self createAnimatorAndBehaviors];

}

- (void) createGestureRecognizer{

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];

[self.view addGestureRecognizer:tap];

}

- (void) handleTap:(UITapGestureRecognizer *)paramTap{

CGPoint tapPoint = [paramTap locationInView:self.view];

if (self.snapBehavior != nil){

[self.animator removeBehavior:self.snapBehavior];

}

self.snapBehavior = [[UISnapBehavior alloc] initWithItem:self.squareView snapToPoint:tapPoint];

self.snapBehavior.damping = 0.5f; //剧列程度

[self.animator addBehavior:self.snapBehavior];

}

- (void) createSmallSquareView{

self.squareView = [[UIView alloc] initWithFrame: CGRectMake(0.0f, 0.0f, 80.0f, 80.0f)];

self.squareView.backgroundColor = [UIColor greenColor];

self.squareView.center = self.view.center;

[self.view addSubview:self.squareView];

}

- (void) createAnimatorAndBehaviors{

self.animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];

UICollisionBehavior *collision = [[UICollisionBehavior alloc] initWithItems:@[self.squareView]];

collision.translatesReferenceBoundsIntoBoundary = YES;

[self.animator addBehavior:collision];

self.snapBehavior = [[UISnapBehavior alloc] initWithItem:self.squareView snapToPoint:self.squareView.center];

self.snapBehavior.damping = 0.5f; /* Medium oscillation */

[self.animator addBehavior:self.snapBehavior];

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