在 ios 7 中呈现和关闭模态视图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19474917/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 02:26:34  来源:igfitidea点击:

Presenting and dismissing a modal view in ios 7

iosuiwebviewios7modalviewcontroller

提问by cdub

I have a view controller that has a button on it. The button is the Privacy Policy. When it's clicked it goes to the proper IBAction and I create the privacy controller.

我有一个视图控制器,上面有一个按钮。按钮是隐私政策。单击它时,它会转到正确的 IBAction,然后我创建隐私控制器。

 - IBAction ...
{
    PrivacyPolicyViewController *privacy = [[PrivacyPolicyViewController alloc] init];
    .....
}

I want to create a modal view of the privacy controller that has a UIWebView that animates itself upward and a back button to close it in ios 7. The ways I see online all are ios 6 and seem deprecated.

我想创建一个隐私控制器的模态视图,它有一个向上动画的 UIWebView 和一个后退按钮以在 ios 7 中关闭它。我在网上看到的所有方式都是 ios 6,似乎已被弃用。

回答by Jano

Use something like this:

使用这样的东西:

// assuming your controller has identifier "privacy" in the Storyboard
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
PrivacyPolicyViewController *privacy = (PrivacyPolicyViewController*)[storyboard instantiateViewControllerWithIdentifier:@"privacy"];

// present
[self presentViewController:privacy animated:YES completion:nil];

// dismiss
[self dismissViewControllerAnimated:YES completion:nil];

回答by creative_rd

[self presentmodalviewcontroller:vc];has been deprecated.

[self presentmodalviewcontroller:vc];已被弃用

you can try for

你可以试试

[self presentViewController:viewController animated:YES completion:nil];

it will work for you..

它会为你工作..

回答by inorganik

If you are using Storyboards, you can use a segue to present a modal view controller as well, and do it programmatically.

如果您使用 Storyboards,您也可以使用 segue 来呈现模态视图控制器,并以编程方式进行。

  1. In your storyboard, ctrl+drag from the File's owner icon in the bar under the starting view to the view you want to present modally, let go and select "modal".
  2. click on the segue icon, and then in the Attributes inspector, give it an identifier, like "toNewView".
  3. in your starting view controller's .m file, use this code to perform the modal segue: [self performSegueWithIdentifier:@"toNewView" sender:self];
  1. 在您的故事板中,按住 ctrl+从起始视图下栏中的文件所有者图标拖动到您要以模态方式呈现的视图,松开并选择“模态”。
  2. 单击 segue 图标,然后在属性检查器中,为其指定一个标识符,例如“toNewView”。
  3. 在您的起始视图控制器的 .m 文件中,使用此代码执行模态转场: [self performSegueWithIdentifier:@"toNewView" sender:self];

It's a nice clean way to do it because you don't have to import a .h file to instantiate the second controller object for the presentViewControllermethod.

这是一个很好的干净方法,因为您不必导入 .h 文件来实例化该presentViewController方法的第二个控制器对象。

To dismiss it, you just use an unwind segue.

要关闭它,您只需使用unwind segue

回答by NRV

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
taskQueeDetails *privacy = (taskQueeDetails*)[storyboard instantiateViewControllerWithIdentifier:@"taskQueeDetails"];

// Present the modal
[self presentViewController:privacy animated:YES completion:nil];

use the code and change the string instantiateViewControllerWithIdentifier:@"taskQueeDetails"]; it will work fine

使用代码并更改字符串instantiateViewControllerWithIdentifier:@"taskQueeDetails"]; 它会正常工作