在我的应用程序中,我有一个tapGesture,panGesture,rotationGesture和pinchGesture。 tapGesture是所有手势的起点,它向我展示了哪些子视图被选中。
在我输入一个处理ImagePicker的按钮后,子视图仍处于选中状态,因此它仍在处理手势。
我的问题:是否有任何声明停止处理手势?
修改
我不需要gestureRecognizer,因此我将它们设为非活动状态:
panRecognizer.enabled = NO;
pinchRecognizer.enabled = NO;
rotationRecognizer.enabled = NO;
所以,如果我需要它们,我想在处理tapRecognizer时让它们工作, 但是识别器在这里不会从非活动状态转变为活动状态。
[panRecognizer isEnabled];
pinchRecognizer.enabled = YES;
rotationRecognizer.enabled = YES;
修改
我的视图是ViewController,子视图位于imageView上 识别器被分配给self.imageView 在第一种方法中,我禁用了识别器,在第二种方法中,我启用了它们
- (IBAction)photo: (id) sender {
panRecognizer.enabled = NO;
pinchRecognizer.enabled = NO;
rotationRecognizer.enabled = NO;
UIImagePickerController* picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.allowsEditing = NO;
@try {
picker.sourceType=UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:picker animated:YES];
}
@catch (NSException * e) {
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:@"Error" message:@"Camera is not available"
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
[alert show];
}
[picker release];
}
- (IBAction)oneTap: (UIGestureRecognizer*)gestureRecognizer {
NSLog(@"oneTap");
float differenz = 2000;
[panRecognizer isEnabled];
pinchRecognizer.enabled = YES;
rotationRecognizer.enabled = YES;
for (UIView* const subview in array) {
subview.opaque = YES;
CGPoint const point = [gestureRecognizer locationInView:self.imageView];
float zwischenS = sqrt(powf(point.x - subview.frame.origin.x,2)) + sqrt(powf(point.y - subview.frame.origin.y,2));
if (differenz > zwischenS ) {
differenz = sqrt(powf(point.x - subview.frame.origin.x,2)) + sqrt(powf(point.y - subview.frame.origin.y,2));
newView.layer.borderColor = [[UIColor clearColor]CGColor];
newView = subview;
subview.layer.borderColor = [[UIColor whiteColor]CGColor];
subview.layer.borderWidth = 3.0f;
[imageView bringSubviewToFront: subview];
}
}
}
我的错误是什么?
提前致谢
答案 0 :(得分:4)
属性[UIGestureRecognizer enabled]
答案 1 :(得分:2)
//YOU CREATE GESTURES LIKE THIS
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc]
initWithTarget:self action:@selector(handlePanGesture:)];
//YOU ADD THEM LIKE THIS
[self.view addGestureRecognizer:panGesture];
//AND YOU REMOVE THEM LIKE THIS
[self.view removeGestureRecognizer:panGesture];
我不确定你是如何编码的,但我希望这会给你一个想法