There are two solutions in my mind.
- To animate uiview, please write a new class that inherits from the UIView class and implements touch delegates instead of writing Gustures to handle the animation (if touch delegates do not start in the current class).
2. I successfully uninstalled the UILongPressGestureRecognizer after it started once.
Please refer to the code below. let me in if you have any questions
The steps that I followed
I added UIView as "myView" to my main view when loading the main view.
I gave the myView tag (you can give 1,2,3 ... etc.) to distinguish the displayed view from the subviews of the main view.
Assign a UILongPressGestureRecognizer gesture to myView and assign the target as the moveMe method.
When the user clicks myView long, the moveMe method is launched.
Then I repeated mainview Subviews with the condition Tag == 1
I removed UILongPressGestureRecognizer from subview.As we can know that TagView 1 of the main view of subView is myView.
So, NSLog (gesture "@ deleted"); and NSLog (@ "moveMe"); will enter the console only at a time.
NSLog (@ "touchhesBegan"); it starts, not the moveMe method first.
Then NSLog (@ "touchhesBegan"); will always work after deleting gestures. The moveMe method will never run.
the code
- (void)viewDidLoad { //Adding to UIView to main view when application is loading. UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 80, 80)]; myView.backgroundColor = [UIColor viewFlipsideBackgroundColor]; myView.tag = 1; //adding a tag to identify it. //Adding Long Press Gesture to the UIView. UILongPressGestureRecognizer *myGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(moveMe:)]; [myView addGestureRecognizer:myGesture]; [myGesture release]; myGesture = nil; [self.view addSubview:myView]; [myView release]; myView = nil; [super viewDidLoad]; } //Method to trigger when user pressed long on the added UIView. -(void)moveMe:(id)sender { for (UIView *subViews in [self.view subviews]) { if (subViews.tag == 1) { [subViews removeGestureRecognizer:sender]; NSLog(@"gesture removed"); } } NSLog(@"moveMe"); } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"touchesBegan"); }
or refer to Disable iOS gesture recognizer