我在做什么:
在我的应用中,我使用以下代码展示了一个模态视图控制器(包含应用设置):
In my app, I'm presenting a modal view controller (containing app settings) using the following code:
optionsViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentModalViewController:optionsViewController animated:YES];
这个过渡只是将视图的底部卷起以显示一些设置.(有关示例,请参阅地图"应用程序.)当您点击页面的上半部分时,原始视图仍然存在但呈灰色显示,模式视图控制器会自动关闭(由操作系统处理,我没有)t 代码).
This transition just curls up the bottom part of the view to expose a few settings. (See the 'Maps' app for an example.) When you tap on the top half of the page, where the original view is still there but grayed out, the modal view controller is automatically dismissed (handled by the OS, I didn't code for this).
-
什么不起作用:
这在 iOS 4 中运行良好(事实上,我的应用目前在 App Store 上).但在 iOS 5 中,Apple 似乎改变了这种转换的行为,并且视图控制器不再关闭自己.我正在尝试复制操作系统之前处理的行为,但不知道如何去做.
This is working fine in iOS 4 (my app is currently on the App Store in fact). But in iOS 5, it looks like Apple have changed the behavior of this transition, and the view controller no longer dismisses itself. I'm trying to replicate the behavior that was handled by the OS before, but can't figure out how to.
-
我的尝试:
在选项视图的顶部添加一个不可见的按钮不起作用.然后页面完全卷曲,这是我不想要的.
Adding an invisible button to the top of the options view doesn't work. The page then curls up the full way, which I don't want.
除此之外,我被困住了.我应该如何复制它最初的工作方式(或者我从一开始就做错了!).非常感谢任何帮助!
Apart from this, I'm stuck. How should I replicate how this worked originally (or was I doing it the wrong way from the start!). Any help is much appreciated!
老兄,我遇到了同样的问题.. 这是我发现使用 parentViewController 的:
Dude, I ran into the same problem.. and here is what I found about using parentViewController:
请注意,从 5.0 开始,这不再是将返回呈现视图控制器.
Note that as of 5.0 this no longer will return the presenting view controller.
这是写在 UIViewController 的头文件中的...
This was written in the header file of UIViewController...
我正在使用 ShareKit,modalViewController 在 iOS4 中运行良好,但在 iOS5 中,它不会自行关闭!这是因为在他们的代码中,他们使用的是:
I am using ShareKit, and the modalViewController was working perfectly in iOS4, but in iOS5, it just won't dismiss itself! This is because in their code, they are using:
[[currentView parentViewController] dismissModalViewControllerAnimated:animated];
而 parentViewController 将返回 nil,因为这是一个模态呈现的视图控制器...
and parentViewController will return nil, since this is a modal presented view controller...
通过寻找解决方案,我找到了你的问题.所以,我决定自己解决它:P
By searching for a solution, I found your question.. So, I decided to fix it myself :P
我把上一行改成了这样:
I changed the previous line to this:
[currentView dismissModalViewControllerAnimated:YES];
像魅力一样工作.
根据您对原始问题的解释,有两个答案.这是第二个:
Depending on how you interpret the original question, there are two answers. Here's the second:
在 iOS5 中,模态控制器似乎只会在您单击 curl 时自行关闭,而不是在 curl 或背景上方.在 iOS5 中,为了让模态视图在点击背景或 curl 上方时自动消失,我将以下代码添加到控制器中,以监听模态视图上的点击,但忽略对按钮的点击.当使用带有页面卷曲的模态控制器时,这应该模仿以前版本的 iOS 中的行为.
In iOS5 it seems that the modal controller only dismisses itself when you click the curl, but not above the curl or the backgound. In iOS5, in order to actually get the modal view to dismiss itself when tapping the background or above the curl I added the following code to the controller, to listen to taps on the modal view, but ignore taps to buttons. This should mimic the behavior in previous version of iOS when working with a modal controller with page curl.
- (void)viewDidLoad
{
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
tap.numberOfTapsRequired = 1;
tap.numberOfTouchesRequired = 1;
tap.delegate = self;
[backgroundView addGestureRecognizer:tap];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
//change it to your condition
if ([touch.view isKindOfClass:[UIButton class]]) {
return NO;
}
return YES;
}
- (void)handleTap:(UITapGestureRecognizer *)sender {
[self dismissModalViewControllerAnimated:YES];
}
这篇关于模态视图控制器不会自行关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!