在UIViewController上显示clearColor UIViewController [英] Display clearColor UIViewController over UIViewController

查看:118
本文介绍了在UIViewController上显示clearColor UIViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UIViewController 视图作为另一个 UIViewController 视图之上的子视图/模态,例如subview / modal应该是透明的,并且任何添加到子视图的组件都应该是可见的。问题是我有子视图显示黑色背景而不是有clearColor。我正在尝试将 UIView 设为clearColor而不是黑色背景。有人知道它有什么问题吗?任何建议都表示赞赏。

I have a UIViewController view as a subview/modal on top of another UIViewController view, such as that the subview/modal should be transparent and whatever components is added to the subview should be visible. The problem is that I have is the subview shows black background instead to have clearColor. I'm trying to make UIView as a clearColor not black background. Does anybody know what is wrong with it? Any suggestion appreciated.

FirstViewController.m

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];

[vc setModalPresentationStyle:UIModalPresentationFullScreen];
[self presentModalViewController:vc animated:NO];  

SecondViewController.m

- (void)viewDidLoad 
{
     [super viewDidLoad];
     self.view.opaque = YES;
     self.view.backgroundColor = [UIColor clearColor];
}






已解决:我修复了这些问题。它适用于iPhone和iPad。没有黑色背景的模态视图控制器只是clearColor / transparent。我唯一需要改变的是将 UIModalPresentationFullScreen 替换为 UIModalPresentationCurrentContext 。这有多简单!


RESOLVED: I fixed the issues. It is working so well for both of iPhone and iPad. Modal View Controller with no black background just clearColor/transparent. The only thing that I need to change is I replaced UIModalPresentationFullScreen to UIModalPresentationCurrentContext. How simple is that!

FirstViewController.m

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
vc.view.backgroundColor = [UIColor clearColor];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:vc animated:NO completion:nil];






注意:如果您使用的 modalPresentationStyle 属性 navigationController

FirstViewController.m

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






注意:坏消息是上述解决方案在iOS 7上不起作用。好消息是我修复了iOS7的问题!我向某人寻求帮助,这就是他所说的:

当以模态方式呈现视图控制器时,iOS会从中移除视图控制器查看层次结构的持续时间。虽然模态呈现的视图控制器的视图是透明的,但除了应用程序窗口(黑色)之外,它下面没有任何内容。 iOS 7引入了一种新的模式演示样式, UIModalPresentationCustom ,这会导致iOS不删除所呈现的视图控制器下的视图。但是,为了使用此模式演示文稿样式,您必须提供自己的过渡委托来处理演示文稿并关闭动画。这在WWDC 2013的使用视图控制器进行自定义转换演讲中进行了概述 https:// developer.apple.com/wwdc/videos/?id=218 ,其中还介绍了如何实现自己的转换代理。

When presenting a view controller modally, iOS removes the view controllers underneath it from the view hierarchy for the duration it is presented. While the view of your modally presented view controller is transparent, there is nothing underneath it except the app window, which is black. iOS 7 introduced a new modal presentation style, UIModalPresentationCustom, that causes iOS not to remove the views underneath the presented view controller. However, in order to use this modal presentation style, you must provide your own transition delegate to handle the presentation and dismiss animations. This is outlined in the 'Custom Transitions Using View Controllers' talk from WWDC 2013 https://developer.apple.com/wwdc/videos/?id=218 which also covers how to implement your own transition delegate.

您可以在iOS7中查看我对上述问题的解决方案: https://github.com/hightech / iOS-7-Custom-ModalViewController-Transitions

You may see my solution for the above issue in iOS7: https://github.com/hightech/iOS-7-Custom-ModalViewController-Transitions

推荐答案

已解决:我修复了问题。它适用于iPhone和iPad。没有黑色背景的模态视图控制器只是clearColor / transparent。我唯一需要改变的是将UIModalPresentationFullScreen替换为UIModalPresentationCurrentContext。这有多简单啊!

RESOLVED: I fixed the issues. It is working so well for both of iPhone and iPad. Modal View Controller with no black background just clearColor/transparent. The only thing that I need to change is I replaced UIModalPresentationFullScreen to UIModalPresentationCurrentContext. How simple is that!

FirstViewController.m

FirstViewController.m

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
    vc.view.backgroundColor = [UIColor clearColor];
    self.modalPresentationStyle = UIModalPresentationCurrentContext;
    [self presentViewController:vc animated:NO completion:nil];






注意:如果你正在使用navigationController的modalPresentationStyle属性:


NOTICE: If you are using a modalPresentationStyle property of navigationController:

FirstViewController.m

FirstViewController.m

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






注意:坏消息是上述解决方案在iOS 7上不起作用。好消息是我修复了iOS7的问题!我向某人寻求帮助,这就是他所说的:

当以模态方式呈现视图控制器时,iOS会从中移除视图控制器查看层次结构的持续时间。虽然模态呈现的视图控制器的视图是透明的,但除了应用程序窗口(黑色)之外,它下面没有任何内容。 iOS 7引入了一种新的模式演示样式UIModalPresentationCustom,它使iOS不会删除所呈现的视图控制器下面的视图。但是,为了使用此模式演示文稿样式,您必须提供自己的过渡委托来处理演示文稿并关闭动画。这在WWDC 2013的使用视图控制器进行自定义转换演讲中进行了概述 https:// developer.apple.com/wwdc/videos/?id=218 ,其中还介绍了如何实现自己的转换代理。

When presenting a view controller modally, iOS removes the view controllers underneath it from the view hierarchy for the duration it is presented. While the view of your modally presented view controller is transparent, there is nothing underneath it except the app window, which is black. iOS 7 introduced a new modal presentation style, UIModalPresentationCustom, that causes iOS not to remove the views underneath the presented view controller. However, in order to use this modal presentation style, you must provide your own transition delegate to handle the presentation and dismiss animations. This is outlined in the 'Custom Transitions Using View Controllers' talk from WWDC 2013 https://developer.apple.com/wwdc/videos/?id=218 which also covers how to implement your own transition delegate.

您可以在iOS7中查看我对上述问题的解决方案: https://github.com/hightech / iOS-7-Custom-ModalViewController-Transitions

You may see my solution for the above issue in iOS7: https://github.com/hightech/iOS-7-Custom-ModalViewController-Transitions

这篇关于在UIViewController上显示clearColor UIViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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