在iOS 6中呈现模态视图 [英] Present Modal View in iOS 6

查看:167
本文介绍了在iOS 6中呈现模态视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示模态视图,但我有两个问题:

I want to display a modal view but I have two problems:


  1. iOS 6和I中没有presentModalViewController必须使用presentViewController,它只是显示我的第二个ViewController,如模态segue而不是没有全屏选项的模态窗口,

  1. There is no presentModalViewController in iOS 6 and I have to use presentViewController which is just display my second ViewController like a modal segue not a modal window without full screen option,

我的第二个问题是如何显示UICollectionViewController的模态窗口。我尝试使用presentViewController,但它只适用于ViewController而不是CollectionViewController。

My second problem is how can I show the modal window from UICollectionViewController. I tried to use presentViewController but it just works with ViewController not CollectionViewController.

我想要做的最好的例子就是这个(Instagram)。他们是如何制作这个模态窗口的?是因为它仍然适用于较旧的iOS版本而且还不是iOS 6吗?或者还有另一种方法可以从UICollectionViewController中显示这样的模态窗口吗?

The best example of what I want to do is this (Instagram). How they made this modal window? Is it because it's still working with older iOS versions and it's not iOS 6 yet? Or there is another way to display modal window like this from UICollectionViewController?

谢谢

推荐答案

如果我理解你正在尝试实现的目的是在父级上呈现一个 ViewControllers 并仍然看到父 ViewController 在后台。

If I understood you correctly what you are trying to achieve is to present one of your ViewControllers over the parent and still see the parent ViewController in the background.

第一个解决方案:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
    vc.view.backgroundColor = [UIColor clearColor];
    self.navigationController.modalPresentationStyle = UIModalPresentationCurrentContext; //self.modalPresentationStyle might do a better job here
    [self presentViewController:vc animated:NO completion:nil];

确保 SecondViewController 内容小于你当前的``ViewController`,你可以在StoryBoard \ xib中看到它的背景颜色。背景颜色将清晰,并将产生透明效果。

Make sure your SecondViewController content is smaller than your current ``ViewController` and that you can see the background color of it in StoryBoard \ xib. The background color will be clear and will create the transparency effect.

第二个解决方案:

创建一个容器(iOS 6及更高版本,如果您打算使用Storyboard IB,低于此将允许您创建容器,但只能创建容器)。

Create a Container (iOS 6 and up if you are planning to use the Storyboard IB, lower than that will let you create Containers but only progrematicly).

< img src =https://i.stack.imgur.com/Hea47.pngalt =容器>

设置容器大小3/4父大小并将第二个viewcontroller连接到它。而不是将\推送到你的第二个视图控制器,你只需

Set the container size 3/4 of the parent size and connect the second viewcontroller to it. Instead of segueing \ pushing to your second viewcontroller you can just

myContainer.alpha = 1; 

在屏幕上显示。

这篇关于在iOS 6中呈现模态视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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