zoukankan      html  css  js  c++  java
  • 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下载看看。谢谢,欢迎大家指正,我是新手。

  • 相关阅读:
    TURN协议(RFC5766详解)
    css布局相关:涉及到常见页面样式难点
    关于echart的x轴固定为0-24小时显示一天内的数据
    用于实现tab页签切换页面的angular路由复用策略
    Promise相关学习
    js原型链、继承、this指向等老生常谈却依然不熟的知识点——记录解析
    js中有遍历作用相关的方法详解总结
    rgb格式颜色与#000000格式颜色的转换
    input搜索框的搜索功能
    Fastapi学习总结(上)
  • 原文地址:https://www.cnblogs.com/linxiu-0925/p/5455558.html
Copyright © 2011-2022 走看看