模态视图控制器不会解雇自己 [英] Modal view controller won't dismiss itself

查看:84
本文介绍了模态视图控制器不会解雇自己的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在做什么:

在我的应用中,我正在使用以下内容呈现模态视图控制器(包含应用设置)以下代码:

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中,看起来苹果已经改变了这种转变的行为,而视图控制器不再自我贬低。我试图复制之前由操作系统处理的行为,但无法弄清楚如何。

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

我改变了上一行:

    [currentView dismissModalViewControllerAnimated:YES];

像魅力一样工作。

编辑:根据您对原始问题的解释方式,有两个答案。这是第二个:

Depending on how you interpret the original question, there are two answers. Here's the second:

在iOS5中,模态控制器似乎只在您点击卷曲时自动解散,而不是在卷曲或背景上方。在iOS5中,为了在点击背景或卷曲上方时实际获得模态视图以消除自身,我将以下代码添加到控制器,以监听模态视图上的点击,但忽略点击按钮。当使用带有页面卷曲的模态控制器时,这应该模仿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];
}

这篇关于模态视图控制器不会解雇自己的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆