1

我在用着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
}

拍照.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(我不使用“push”),如下所示:

--->首页

--->拍照(如弹出式节目):它有 2 个按钮“从库中选择照片”和“关闭”

当我使用“从图库中选择照片”功能时,我无法选择照片并且UITapGestureRecognizer总是显示。

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

P/S:对不起我的英语。

4

3 回答 3

1

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

于 2013-11-15T04:14:30.077 回答
0

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

于 2013-11-15T04:15:17.727 回答
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

于 2013-11-15T06:23:40.917 回答