首先,一直以为摇一摇的功能实现好高大上,结果百度了。我自己也模仿写了一个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下载看看。谢谢,欢迎大家指正,我是新手。

最新文章

  1. windows查看端口占用情况
  2. 45、Docker 加 tensorflow的机器学习入门初步
  3. iBatis.Net实现返回DataTable和DataSet对象
  4. android操作XML的几种方式(转)
  5. linux设备驱动归纳总结(二):模块的相关基础概念【转】
  6. EditText控件实现只读
  7. java核心技术记录之java术语
  8. 通过对源代码的反向工程学习CoreData架构
  9. ApkTool动态打包
  10. AFNetworking网络请求的get和post步骤
  11. win2008 ent r2 开启端口
  12. 用C#实现的条形码和二维码编码解码器
  13. headfirst设计模式(7)—命令模式
  14. [LeetCode] 22. 括号生成
  15. OSGI框架
  16. 基于react的MQ管理系统遇到的问题以及解决办法
  17. 如何获取微信小店小程序的AppID
  18. vue 树状图数据的循环 递归循环
  19. 【OS】Heap & Stack
  20. Codeforces 437D The Child and Zoo - 树分治 - 贪心 - 并查集 - 最大生成树

热门文章

  1. LOJ2823 三个朋友 ——查询字串的哈希值
  2. 洛谷P2396 yyy loves Maths VII【状压dp】
  3. 安装pip的三种方式
  4. JQuery制作网页——表单验证
  5. HSSFWorkbook 模版使用
  6. mysql 的编写顺序和执行顺序
  7. Ubuntu 14.04 indigo 安装 cartographer 1.0.0
  8. 模糊查询(附上源码和jquery-1.12.1.js,jquery-ui.js,jquery-ui.css)
  9. docker 笔记--运行中的容器如何添加端口映射
  10. java 通过runtime 调用python 不显示python运行内容的bug