我正在使用UITapGestureRecognizer
这是我的代码:
Home.m
:
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAnim:)];
[self.view addGestureRecognizer:tapGesture];
UIButton *buttontest = [[UIButton alloc] init];
buttontest.backgroundColor = [UIColor whiteColor];
buttontest.frame = CGRectMake(0, 80, 40, 40);
[buttontest addTarget:self action:@selector(test:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:buttontest];
[self.view bringSubviewToFront:buttontest];
}
- (void)test: (UIButton*)aButton {
// TakePhoto *mvc = [[TakePhoto alloc]initWithNibName:@"TakePhoto" bundle:Nil];
// [self.navigationController pushViewController:mvc animated:YES];
//
// [self.view removeFromSuperview];
if (self.companyController) {
self.companyController = nil;
}
self.companyController = [[TakePhoto alloc] initWithNibName:@"TakePhoto" bundle:nil];
UIView *viewSuper = [[IQAppDelegate shareInstance] currentVisibleController].view;
UIViewController *profile = self.companyController;
profile.view.frame = viewSuper.frame;
[viewSuper addSubview:profile.view];
profile.view.frame = CGRectMake(viewSuper.frame.origin.x, viewSuper.frame.size.height, profile.view.frame.size.width, profile.view.frame.size.height);
[UIView beginAnimations:nil context: nil];
[UIView setAnimationDuration:0.35];
profile.view.frame = CGRectMake(viewSuper.frame.origin.x, viewSuper.frame.origin.x, profile.view.frame.size.width, profile.view.frame.size.height);
[UIView commitAnimations];
}
}
- (void) tapAnim: (UITapGestureRecognizer*)gestureRecognizer {
// Show something
}
TakePhoto.m
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
picker.allowsEditing = NO;
[(UIViewController *)self.delegate presentModalViewController:picker animated:YES];
我添加了一个视图:Takephoto Front of Home(我不是用“推”),像这样:
--->首页
--->拍照(如popUp节目):它有2个按钮“从库中选择照片”和“关闭”
当我使用“从图库中选择照片”功能时,我无法选择照片,UITapGestureRecognizer
始终显示。
如何从图库中选择照片时停用UITapGestureRecognizer
?
答案 0 :(得分:1)
手势识别器具有enabled
属性。将其设置为NO
以禁用手势识别器。为了使这更容易,您应该使用实例变量保持对轻击手势识别器的引用。
答案 1 :(得分:0)
您可以在选择照片之前设置tapGesture.enabled=NO
。
答案 2 :(得分:0)
我认为你需要在下面的委托方法中实现: -
- (BOOL)gestureRecognizer:
(UIGestureRecognizer *)gestureRecognizer
shouldReceiveTouch:(UITouch *)touch
当您查看文档时,它将返回YES(默认情况下)以允许手势识别器检查触摸对象,NO以防止手势识别器看到此触摸对象。有关详细信息,请参阅此https://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIGestureRecognizerDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIGestureRecognizerDelegate/gestureRecognizer:shouldReceiveTouch: