問題描述
我在做什么:
在我的應用中,我使用以下代碼展示了一個模態視圖控制器(包含應用設置):
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];
}
這篇關于模態視圖控制器不會自行關閉的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!