iOS开发UIkit动力学UIDynamicAnimator一系列动画
UIDynamicAnimator类,通过这个类中的不同行为来实现一些动态特性。
UIAttachmentBehavior(吸附),UICollisionBehavior(碰撞),UIGravityBehavior(重力),UIPushBehavior(推动),UISnapBehavior(捕捉)。另外还有一个辅助的行为UIDynamicItemBehavior,用来在item层级设定一些参数,比如item的摩擦,阻力,角阻力,弹性密度和可允许的旋转等等。
1.UIAttachmentBehavior(吸附):
- (void)viewDidLoad {
[super viewDidLoad]; self.dynamicAnimation = [[UIDynamicAnimator alloc]initWithReferenceView:self.view];
// 图片
self.imgView = [[UIImageView alloc]initWithFrame:CGRectMake(, , ,)];
self.imgView.image = [UIImage imageNamed:@"dizhijieyong_icon"];
[self.view addSubview:self.imgView];
self.imgView.userInteractionEnabled = YES; // 添加手势
UIPanGestureRecognizer *panGest = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panGestAction:)];
[self.imgView addGestureRecognizer:panGest]; // 吸附 offset可以设置吸附的偏移,anchor是设置锚点
self.attachment = [[UIAttachmentBehavior alloc]initWithItem:self.imgView offsetFromCenter:UIOffsetMake(, ) attachedToAnchor:CGPointMake(, )];
} // 实现一个pan手势,让一个image跟着手势跑 - (void)panGestAction: (UIPanGestureRecognizer *)panGest{ NSLog(@"手势触发啦!!!"); // 取得location
CGPoint location = [panGest locationInView:self.view];
CGPoint boxLocation = [panGest locationInView:self.imgView]; switch (panGest.state) {
// 开始拖拽
case UIGestureRecognizerStateBegan: NSLog(@"you touch started position %@",NSStringFromCGPoint(location));
NSLog(@"location in image started is %@",NSStringFromCGPoint(boxLocation));
// 移除
[self.dynamicAnimation removeAllBehaviors]; UIOffset offSet = UIOffsetMake(boxLocation.x - CGRectGetMidX(self.imgView.bounds),
boxLocation.y - CGRectGetMidY(self.imgView.bounds)); self.attachment = [[UIAttachmentBehavior alloc]initWithItem:self.imgView offsetFromCenter:offSet attachedToAnchor:location];
self.attachment.damping=0.5;
self.attachment.frequency=0.8;
[self.dynamicAnimation addBehavior:self.attachment];
break;
case UIGestureRecognizerStateEnded:
[self.dynamicAnimation removeAllBehaviors];
default:
[self.attachment setAnchorPoint:location];
break;
}
}
2.UIGravityBehavior(重力):
// 实现点击屏幕掉落一张图片的代码 - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ self.gravity = [[UIGravityBehavior alloc]initWithItems:nil];
[self.dynamicAnimation addBehavior:self.gravity]; UIImageView *gravImagView = [[UIImageView alloc]initWithFrame:CGRectMake(, , , )];
gravImagView.image = [UIImage imageNamed:@"zichanlingyong_icon"];
[self.view addSubview:gravImagView];
gravImagView.frame = CGRectMake(, , , );
[self.gravity addItem:gravImagView]; }
3.UISnapBehavior(捕捉):
// UISnapBehavior 将UIView通过动画吸附到某个点上
- (void) handleTap:(UITapGestureRecognizer *)paramTap{
CGPoint tapPoint = [paramTap locationInView:self.view]; if (self.snap != nil){
[self.dynamicAnimation removeBehavior:self.snap];
}
self.snap = [[UISnapBehavior alloc] initWithItem:self.imgView snapToPoint:tapPoint];
self.snap.damping = 0.5f; //剧列程度
[self.dynamicAnimation addBehavior:self.snap];
}
还有一些没有试过,有时间补充吧!!!嘻嘻~~~~~
iOS开发UIkit动力学UIDynamicAnimator一系列动画的更多相关文章
- iOS开发笔记10:圆点缩放动画、强制更新、远程推送加语音提醒及UIView截屏
1.使用CAReplicatorLayer制作等待动画 CALayer+CABasicAnimation可以制作很多简单的动画效果,之前的博客中介绍的“两个动画”,一个是利用一张渐变色图片+CABas ...
- 【Swift】IOS开发中自定义转场动画
在IOS开发中,我们model另外一个控制器的时候,一般都使用默认的转场动画. 其实我们可以自定义一些转场动画.达到不同的转场效果. 步骤如下:(photoBrowser是目标控制器) 1.在源控制器 ...
- iOS开发UIKit框架-可视化编程-XIB
1. Interface Builder 可视化编程 1> 概述 GUI : 图形用户界面(Graphical User Interface, 简称GUI, 又称图形化界面) 是指采用图形方式显 ...
- ios开发之简单实现loading动画效果
最近有朋友问我类似微信语音播放的喇叭动画和界面图片加载loading界面是怎样实现的,是不是就是一个gif图片呢!我的回答当然是否定了,当然不排除也有人用gif图片啊!下面我就来罗列三种实现loadi ...
- iOS开发--QQ音乐练习,旋转动画的实现,音乐工具类的封装,定时器的使用技巧,SliderBar的事件处理
一.旋转动画的实现 二.音乐工具类的封装 -- 返回所有歌曲,返回当前播放歌曲,设置当前播放歌曲,返回下一首歌曲,返回上一首歌曲方法的实现 头文件 .m文件 #import "ChaosMu ...
- ios开发——实用技术篇&三维旋转动画
实现三位旋转动画的方法有很多种,这里介绍三种 一:UIView 1 [UIView animateWithDuration:1.0 animations:^{ 2 self.iconView.laye ...
- iOS开发之--UIImageView的animationImages动画
图片动画实现,代码如下: -(UIImageView *)animationImageView { if (!_animationImageView) { _animationImageView= [ ...
- IOS开发学习笔记022-imageView实现动画
这里要播放的动画是很多张连续的动画,连续播放就会显示出动画效果. 大概过程是: 新建一个single view application ,然后添加一个image View控件到视图.给image vi ...
- ios开发图层layer与核心动画二:CATransform3D,CAlayear和UIView区别,layer的position和anchorpoint
一:CATransform3D #import "ViewController.h" @interface ViewController () @property (weak, n ...
随机推荐
- 配置linux ftp服务器,客户端报list remote folder fail
XFTP出现列表文件夹失败.主要是因为FTP模式不对,应该为主动连接模式, 可以在设置主机属性 - 选项页签 - 将默认勾选的“使用被动模式”(使用消极模式)的多选框取消...就可以了...
- 牛客练习赛53 A 超越学姐爱字符串 (DP)
牛客练习赛53 超越学姐爱字符串 链接:https://ac.nowcoder.com/acm/contest/1114/A来源:牛客网 超越学姐非常喜欢自己的名字,以至于英文字母她只喜欢" ...
- jquery属性方法hasClass判断是否存在某个class
判断匹配集合中是否存在至少一个元素使用样式'selected',存在则返回'true',不存在为'flase'. <html> <head> <script src=&q ...
- P5025 [SNOI2017]炸弹 题解
蒟蒻的第一篇黑题题解(学了这么长时间了才第一道也是没谁了.) 题目链接: Solution: 朴素: 根据题目描述,我们可以处理每一个x节点左右爆炸半径范围内的点,然后模拟一次爆炸 (for),遍历每 ...
- 微信小程序实现连接蓝牙设备跑步APP
背景 微信小程序兴起,有变成超级APP的趋势,通过微信提供的小程序api,可以通过微信调用到手机原生的支持. 目标 通过微信小程序实现来实现跑步类App的功能. 需求分析 跑步类App需要的两个核心的 ...
- 关于.ssh出错,无法从远程git仓库拉代码
背景:从windows开发环境改到ubuntu,将windows下生成的.ssh文件拷贝到ubuntu下,以clone远程git仓库代码 错误:sign_and_send_pubkey: signin ...
- 写出一条SQL语句:取出表A中第31到40行记录(SQLserver,以自增长的ID作为主键,注意: 一条Sql语句:取出表A中第31到第40记录
解1: select top 10 * from A where id not in (select top 30 id from A) 解2: select top 10 * from A wher ...
- chown 与 chgrp 修改权限用户
# 改变权限 chmod 777 filepath # 改变所有者 chown test filepath # 改变所属组 chgrp user filepath chown='change own ...
- [Cogs] 最大数maxnumber
http://cogs.pro:8080/cogs/problem/problem.php?pid=1844 Luogu 的数据真zhizhang Cogs AC #include <iostr ...
- Codevs 1169 传纸条 2008年NOIP全国联赛提高组
1169 传纸条 2008年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 钻石 Diamond 题目描述 Description 小渊和小轩是好朋友也是同班 ...