- (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类,包含上述方法,在需要闪动的地方,视图调用该方法即可。