gpt4 book ai didi

iphone - 模态视图 Controller 不会自行解散

转载 作者:太空狗 更新时间:2023-10-30 03:08:44 25 4
gpt4 key购买 nike

我在做什么:

在我的应用程序中,我使用以下代码呈现模态视图 Controller (包含应用程序设置):

    optionsViewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentModalViewController:optionsViewController animated:YES];

这个过渡只是卷起 View 的底部以暴露一些设置。 (有关示例,请参见“ map ”应用程序。)当您点击页面的上半部分时,原始 View 仍然存在但变灰,模态视图 Controller 将自动关闭(由操作系统处理,我没有' t 代码)。

-

什么不起作用:

这在 iOS 4 中运行良好(我的应用程序目前实际上在 App Store 上)。但在 iOS 5 中,Apple 似乎已经改变了这种转换的行为, View Controller 不再自行解散。我正在尝试复制之前由操作系统处理的行为,但不知道该怎么做。

-

我尝试过的:

在选项 View 的顶部添加一个不可见的按钮不起作用。然后页面完全 curl ,这是我不想要的。

除此之外,我被卡住了。我应该如何复制它最初的工作方式(或者我从一开始就以错误的方式做这件事!)。非常感谢任何帮助!

最佳答案

伙计,我遇到了同样的问题..这是我发现的关于使用 parentViewController 的内容:

Note that as of 5.0 this no longer will return the presenting view controller.

这个写在UIViewController的头文件里...

我正在使用 ShareKit,并且 modalViewController 在 iOS4 中工作得很好,但在 iOS5 中,它不会自行消失!这是因为在他们的代码中,他们使用:

    [[currentView parentViewController] dismissModalViewControllerAnimated:animated];

parentViewController 将返回 nil,因为这是一个模态呈现的 View Controller ...

通过搜索解决方案,我找到了你的问题。所以,我决定自己解决它:P

我将上一行更改为:

    [currentView dismissModalViewControllerAnimated:YES];

像魅力一样工作。


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

在 iOS5 中,模态 Controller 似乎只在您单击 curl 时自行关闭,但不会在 curl 或背景之上。在 iOS5 中,为了真正让模态视图在点击背景或 curl 上方时自行消失,我将以下代码添加到 Controller 中,以收听模态视图上的点击,但忽略对按钮的点击。当使用带有页面 curl 的模态 Controller 时,这应该模仿以前版本的 iOS 中的行为。

- (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];
}

关于iphone - 模态视图 Controller 不会自行解散,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6557425/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com