UISnapBehavior-动画效果:迅猛移动弹跳摆动
2013-12-06 17:10
239 查看
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];
}
而这个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];
}
相关文章推荐
- UISnapBehavior-动画效果:迅猛移动弹跳摆动
- UISnapBehavior-动画效果:迅猛移动弹跳摆动
- UIAttachmentBehavior-动画效果:依附,关联
- iOS-UIDynamicAnimator和UISnapBehavior动画示例(iOS打分动画)
- 动态移动UI控件的位置并带有动画的效果
- AndroidUI 视图动画-移动动画效果 (TranslateAnimation)
- UIDynamicItemBehavior-动画效果:增加各种物理特性
- AndroidUI 视图动画-移动动画效果 (TranslateAnimation)
- AndroidUI 视图动画-移动动画效果 (TranslateAnimation)
- 【Android UI设计与开发】第18期:滑动菜单栏(三)SlidingMenu动画效果的实现
- IOS-购物车动画效果(图片移动)
- 属性动画实现控件类似贝塞尔曲线轨迹移动效果
- 【移动开发】为ViewGroup的子视图添加动画效果
- js 实现简单的动画效果(小圆移动)
- AndroidUI 视图动画-透明动画效果 (AlphaAnimation)
- AndroidUI 视图动画-缩放动画效果 (ScaleAnimation)
- 系统 UI 动画效果导致的bug
- iOS-UIDynamic物理仿真-捕捉-UISnapBehavior
- Android UI开发第十二篇——动画效果Animation(一)
- 猫猫学IOS(四十)UI之核心动画_抖动效果_CAKeyframeAnimation