# Import "LHViewController. h" # Define angelToRandian (x)/180.0 * M_PI) @ Interface LHViewController () @ Property (strong, nonatomic) IBOutlet UIImageView * imageView; @ End @ Implementation LHViewController -(Void) viewDidLoad { [Super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. UILongPressGestureRecognizer * longPress = [[UILongPressGestureRecognizer alloc] initWithTarget: self action: @ selector (longPress :)]; [Self. imageView addGestureRecognizer: longPress]; } -(Void) longPress :( UILongPressGestureRecognizer *) longPress { If (longPress. state = UIGestureRecognizerStateBegan ){ CAKeyframeAnimation * anim = [CAKeyframeAnimation animation]; Anim. keyPath = @ "transform. rotation "; Anim. values = @ [@ (angelToRandian (-7), @ (angelToRandian (7), @ (angelToRandian (-7)]; Anim. repeatCount = MAXFLOAT; Anim. duration= 0.2; [Self. imageView. layer addAnimation: anim forKey: nil]; Self. btn. hidden = NO; } } -(IBAction) delete :( id) sender { [Self. imageView removeFromSuperview]; [Self. btn removeFromSuperview]; } @ End |