现在的位置: 首页 > 综合 > 正文

视图长按添加闪动效果

2014年03月23日 ⁄ 综合 ⁄ 共 1013字 ⁄ 字号 评论关闭

- (void)shakeStatus:(BOOL)enabled

{

    if (enabled)

    {

        CGFloat rotation = 0.03;

        

        CABasicAnimation *shake = [CABasicAnimation animationWithKeyPath:@"transform"];

        shake.duration = 0.13;

        shake.autoreverses = YES;

        shake.repeatCount  = MAXFLOAT;

        shake.removedOnCompletion = NO;

        shake.fromValue = [NSValue valueWithCATransform3D:CATransform3DRotate(self.layer.transform,-rotation, 0.0 ,0.0 ,1.0)];

        shake.toValue   = [NSValue valueWithCATransform3D:CATransform3DRotate(self.layer.transform, rotation, 0.0 ,0.0 ,1.0)];

        

        [self.layer addAnimation:shake forKey:@"shakeAnimation"];

    }

    else

    {

        [self.layer removeAnimationForKey:@"shakeAnimation"];

    }

}

 UILongPressGestureRecognizer * _longPressGesture = [[UILongPressGestureRecognizer
alloc] initWithTarget:self
action:@selector(longPressGestureUpdated:)];

    _longPressGesture.numberOfTouchesRequired =
1;

    _longPressGesture.delegate =
self
;

    _longPressGesture.cancelsTouchesInView =
NO
;

    [self.view
addGestureRecognizer:_longPressGesture];

步骤:给uiview创建一个category类,包含上述方法,在需要闪动的地方,视图调用该方法即可。

抱歉!评论已关闭.