I want to implement an app icon (on home screen) like behavior. So I need two functionality in there.
- Wobble on Long Press and display a delete icon
- Press the delete icon and remove the view.
I could get No 1 correctly, via this person of code.
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
[longPress setMinimumPressDuration:1];
[view addGestureRecognizer:longPress];
- (void)longPress:(UILongPressGestureRecognizer*)gesture {
if ( gesture.state == UIGestureRecognizerStateBegan ) {
CGAffineTransform leftWobble = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(-5));
CGAffineTransform rightWobble = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(5.0));
view.transform = leftWobble; // starting point
UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
deleteButton.frame = CGRectMake(-4, 0, 43, 54);
[view addSubview: deleteButton];
[view bringSubviewToFront:deleteButton];
[deleteButton setBackgroundImage:[UIImage imageNamed:@"trashcan.png"] forState:UIControlStateNormal];
[deleteButton addTarget:self action:@selector(deletePressed:) forControlEvents:UIControlEventTouchUpInside];
[UIView animateWithDuration:0.5 delay:0 options:( UIViewAnimationOptionAutoreverse|UIViewAnimationOptionRepeat|UIViewAnimationOptionCurveEaseInOut) animations:^{
view.transform = rightWobble;
}completion:^(BOOL finished){
view.transform = CGAffineTransformIdentity;
}];
}
}
Now I expected the deletePressed to get triggered when the view is wobbly and delete button is pressed. But that never gets trigger. Please help me find out what is going wrong.