2013-11-15 45 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

相關問題