美文网首页
iOS实现微信摇一摇动画

iOS实现微信摇一摇动画

作者: 獨荹儛臨 | 来源:发表于2018-02-26 15:09 被阅读31次

- (void)viewDidLoad {

    [superviewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.view.layer.contents= (id)[UIImageimageNamed:@"ShakeforsongBgshade"].CGImage;
}

- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent*)event
{
    NSLog(@"摇一摇开始");
    CGFloatoffset =25;
    CABasicAnimation*animation = [CABasicAnimationanimationWithKeyPath:@"transform.translation.y"];

    animation.duration=1;
    animation.toValue=@(-offset);
    animation.autoreverses=YES;
    [self.topImageView.layeraddAnimation:animationforKey:nil];
    animation.toValue=@(offset);
    [self.bottomImageView.layeraddAnimation:animationforKey:nil];
}

#define kToDadian(x) (M_PI/180* (x))
//iphone删除应用动画
- (void)longPressHandle:(UILongPressGestureRecognizer*)longPress
{
    //长按开始
    if(longPress.state==UIGestureRecognizerStateBegan)
    {
        //关键帧支持下面的key:rotation,scale,translation.面表格里面的key前面都需要加上transform
        CAKeyframeAnimation*animation = [CAKeyframeAnimationanimationWithKeyPath:@"transform.rotation.z"];

        animation.values=@[@(kToDadian(5)),
                           @(kToDadian(0)),
                           @(kToDadian(-5)),
                           @(kToDadian(0))];

        animation.repeatCount=MAXFLOAT;
        animation.duration=0.2;
        [longPress.view.layeraddAnimation:animationforKey:@"animationKey"];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4*NSEC_PER_SEC)),dispatch_get_main_queue(), ^{
            [longPress.view.layerremoveAnimationForKey:@"animationKey"];
        });
    }
}

相关文章

网友评论

      本文标题:iOS实现微信摇一摇动画

      本文链接:https://www.haomeiwen.com/subject/cxsyxftx.html