2013-11-15 33 views
1

我使用UITapGestureRecognizer如何从库中选择照片时禁用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家门前的(我'不使用'推“),像这样:

--->首页

--->拍照(如弹出窗口显示):它有2个按钮“选择从库中的照片”和“关闭”

当我使用功能“从图库中选择照片“,我不能选择一张照片和UITapGestureRecognizer总是显示。

如何禁用UITapGestureRecognizer从图库中选择照片?

P/S:抱歉我的英语。

+0

您是否在viewcontroller.view上尝试过userInteractionEnabled = NO? –

+0

是的,我做到了。但是,当设置userInteractionEnable = NO,我不能点击任何东西。 – TienLe

回答

1

手势识别器具有enabled属性。将其设置为NO以禁用手势识别器。为了使这更容易,您应该使用实例变量保留对轻击手势识别器的引用。

+0

我只是设置启用=否,但我不能点击选择照片。 – TienLe

+0

更新您的问题,提供更多关于“从图库中选择照片”功能的详细信息(和代码)。 – rmaddy

0

在选择照片之前,您可以设置tapGesture.enabled=NO

0

我认为你需要执行下面的委托方法如下: -

- (BOOL)gestureRecognizer: 
(UIGestureRecognizer *)gestureRecognizer 
shouldReceiveTouch:(UITouch *)touch 

当你看的文件,将返回YES(默认),以允许手势识别检查触摸对象,否防止手势识别器看到该触摸对象。有关更多详细信息,请参阅https://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIGestureRecognizerDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intfm/UIGestureRecognizerDelegate/gestureRecognizer:shouldReceiveTouch

相关问题