0

在我的应用程序中,我使用了 presentModalViewController,在下一个控制器中,我使用了 UIScrollView,也使用了关闭 presentModalViewController UITapGestureRecognizer

我的代码就像,

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tappedOnView:)]; tapGesture.numberOfTapsRequired = 1; tapGesture.numberOfTouchesRequired = 1; tapGesture.delegate = self; [self.fullScreenImageView addGestureRecognizer:tapGesture];

-(void)tappedOnView:(UIGestureRecognizer*)gestureRecognizer {
    [self dismissModalViewControllerAnimated:YES];}

但这给了我一个错误

attempt to dismiss modal view controller whose view does not currently appear. self = <UITabBarController: 0xabb0610> modalViewController = <FullScreenViewController: 0xab5c440>

所以我替换了调用方式

if ([self respondsToSelector:@selector(presentingViewController)]) {
    [self.presentingViewController.presentingViewController dismissModalViewControllerAnimated:YES]; // for IOS 5+
} else {
    [self.parentViewController.parentViewController dismissModalViewControllerAnimated:YES]; // for pre IOS 5
}

但是代码不起作用。我不能解雇我的 presentModalViewController。没有滚动视图它的工作。上面的代码有什么问题?

4

1 回答 1

0

tapGesture.delegate = 自我;

那里不需要。

[self.fullScreenImageView addGestureRecognizer:tapGesture];

如果 fullScreenImageView 是一个滚动视图,那么 tapGesture 已经在那里实现了。这可能是问题所在。

于 2013-03-25T14:47:35.867 回答