在ios 7中呈现和消除模态视图

cdu*_*dub 11 uiwebview modalviewcontroller ios ios7

我有一个视图控制器,上面有一个按钮.该按钮是隐私政策.当它被点击时,它会转到正确的IBAction,我创建了隐私控制器.

 - IBAction ...
{
    PrivacyPolicyViewController *privacy = [[PrivacyPolicyViewController alloc] init];
    .....
}
Run Code Online (Sandbox Code Playgroud)

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

Jan*_*ano 47

使用这样的东西:

// 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];
Run Code Online (Sandbox Code Playgroud)


cre*_*_rd 9

[self presentmodalviewcontroller:vc];已被弃用.

你可以尝试

[self presentViewController:viewController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)

它会为你工作..


ino*_*nik 6

如果您使用的是Storyboard,则可以使用segue来呈现模态视图控制器,并以编程方式执行.

  1. 在故事板中,按住Ctrl键并从起始视图下方栏中的文件所有者图标拖动到要模拟显示的视图,然后选择"模态".
  2. 单击segue图标,然后在Attributes检查器中,为其指定一个标识符,如"toNewView".
  3. 在您的起始视图控制器的.m文件中,使用此代码执行模式segue: [self performSegueWithIdentifier:@"toNewView" sender:self];

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

要解雇它,你只需使用展开segue.