iOS-类似微信摇一摇
首先,一直以为摇一摇的功能实现好高大上,结果百度了。我自己也模仿写了一个demo。主要代码如下:
新建一个项目,名字为AnimationShake。
主要代码:
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
}
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
if (motion == UIEventSubtypeMotionShake )
{
// User was shaking the device. Post a notification named "shake".
[[NSNotificationCenter defaultCenter] postNotificationName:@"shake" object:self];
}
}
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
}
-(void)addAnimations{
AudioServicesPlaySystemSound(_soundID);
//让imgup上下移动
CABasicAnimation *translation2 = [CABasicAnimation animationWithKeyPath:@"position"];
translation2.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
translation2.fromValue = [NSValue valueWithCGPoint:CGPointMake(160, 115)];
translation2.toValue = [NSValue valueWithCGPoint:CGPointMake(160, 40)];
translation2.duration = 0.4;
translation2.repeatCount = 1;
translation2.autoreverses = YES;
//让imagdown上下移动
CABasicAnimation *translation = [CABasicAnimation animationWithKeyPath:@"position"];
translation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
translation.fromValue = [NSValue valueWithCGPoint:CGPointMake(160, 345+44+20)];
translation.toValue = [NSValue valueWithCGPoint:CGPointMake(160, 420)];
translation.duration = 0.4;
translation.repeatCount = 1;
translation.autoreverses = YES;
[_imgDown.layer addAnimation:translation forKey:@"translation"];
[_imgUp.layer addAnimation:translation2 forKey:@"translation2"];
}
源码可以去我的github网站:https://github.com/linxiu下载看看。谢谢,欢迎大家指正,我是新手。
最新文章
- windows查看端口占用情况
- 45、Docker 加 tensorflow的机器学习入门初步
- iBatis.Net实现返回DataTable和DataSet对象
- android操作XML的几种方式(转)
- linux设备驱动归纳总结(二):模块的相关基础概念【转】
- EditText控件实现只读
- java核心技术记录之java术语
- 通过对源代码的反向工程学习CoreData架构
- ApkTool动态打包
- AFNetworking网络请求的get和post步骤
- win2008 ent r2 开启端口
- 用C#实现的条形码和二维码编码解码器
- headfirst设计模式(7)—命令模式
- [LeetCode] 22. 括号生成
- OSGI框架
- 基于react的MQ管理系统遇到的问题以及解决办法
- 如何获取微信小店小程序的AppID
- vue 树状图数据的循环 递归循环
- 【OS】Heap &; Stack
- Codeforces 437D The Child and Zoo - 树分治 - 贪心 - 并查集 - 最大生成树
热门文章
- LOJ2823 三个朋友 ——查询字串的哈希值
- 洛谷P2396 yyy loves Maths VII【状压dp】
- 安装pip的三种方式
- JQuery制作网页——表单验证
- HSSFWorkbook 模版使用
- mysql 的编写顺序和执行顺序
- Ubuntu 14.04 indigo 安装 cartographer 1.0.0
- 模糊查询(附上源码和jquery-1.12.1.js,jquery-ui.js,jquery-ui.css)
- docker 笔记--运行中的容器如何添加端口映射
- java 通过runtime 调用python 不显示python运行内容的bug