iOS 按键 抖动

来源:互联网 发布:小气泡清洁的危害 知乎 编辑:程序博客网 时间:2024/05/16 08:52
- (void)shake{        CABasicAnimation *moveAnimation = [CABasicAnimation animationWithKeyPath:@"position.x"];    moveAnimation.byValue = [NSNumber numberWithFloat:50.0];    // Here's the important part    [moveAnimation setDuration:0.1];    [moveAnimation setBeginTime:0.0];    moveAnimation.fillMode = kCAFillModeForwards;        CABasicAnimation *borderWidthAnimation = [CABasicAnimation animationWithKeyPath:@"borderWidth"];    [borderWidthAnimation setFromValue:[NSNumber numberWithFloat:0.0]];    [borderWidthAnimation setToValue:[NSNumber numberWithFloat:20.0]];    // Here's the important part    [borderWidthAnimation setDuration:10.0];    [borderWidthAnimation setBeginTime:5.0];    //kCAMediaTimingFunctionLinear kCAMediaTimingFunctionEaseInEaseOut    borderWidthAnimation.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];        CASpringAnimation *springAnimation = [CASpringAnimation animationWithKeyPath:@"position.x"];    [springAnimation setDuration: 1.0];    [springAnimation setBeginTime:0.1];    springAnimation.stiffness = 100;    springAnimation.damping = 10;    springAnimation.initialVelocity = 15.0;    springAnimation.byValue = [NSNumber numberWithFloat:-50.0];        CAAnimationGroup *group = [CAAnimationGroup animation];    [group setDuration:1.0];        [group setAnimations:[NSArray arrayWithObjects:moveAnimation, springAnimation, nil]];        [self.ViewTest.layer addAnimation:group forKey:nil];    self.ViewTest.layer.borderColor = [UIColor yellowColor].CGColor;}


//方法二:

//        CABasicAnimation *shakeAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.y"];        CABasicAnimation *shakeAnimation = [CABasicAnimation animationWithKeyPath:@"transform.translation.x"];        shakeAnimation.duration = 0.25f;        //        shakeAnimation.duration = 0.5f;                shakeAnimation.fromValue = [NSNumber numberWithFloat:-5];        shakeAnimation.toValue = [NSNumber numberWithFloat:5];        shakeAnimation.autoreverses = YES;        [_imageView.layer addAnimation:shakeAnimation forKey:nil];



0 0