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];
}
而这个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];
}
相关文章推荐
- 事件传递和UIResponder
- Android 更新UI的两种方法——handler和runOnUiThread()
- Building Block(并查集)
- UISegmentedControl + UISlider +UIImageView的动画效果
- 去掉UItableview headerview黏性
- ue32编辑器光标怎么变成方的了,不方便啊,怎么改呢?
- 用requests和beautifulsoup爬取豆瓣电影top250,代码及遇到的问题
- iOS 小经验:UIAnimation空对象导致crash
- mysql prepareStatement executeQuery() 内存溢出的解决办法
- Maximum Subsequence Sum【最大连续子序列+树状数组解决】
- Build Systems to Be Zuhanden
- SequenceInputStream(序列流)
- UIViewAnimationOptions类型
- N-Queens II
- DB 查询分析器 6.04 在 Windows 10 上的安装与运行展示
- 用UIKIT的模态对话框要注意的地方
- 基于requests实现极客学院课程爬虫
- UIImage与UIColor互转
- shop++ CriteriaQuery 数据库查询语句
- require/include