ios - UIViewController透明背景

标签 ios xcode

我正在以这种方式创建一个 View Controller :

 UIStoryboard *sb = [UIStoryboard storyboardWithName:@"PhotoViewControlleriPhone" bundle:nil];
                                UIViewController *vc = [sb instantiateInitialViewController];

                               vc.view.backgroundColor = [UIColor clearColor];
                               self.modalPresentationStyle = UIModalPresentationCurrentContext;

                               [self presentModalViewController:vc animated:NO];

                               vc.view.frame = CGRectMake(imageView.frame.origin.x, imageView.frame.origin.y + 64, imageView.frame.size.width, 200.000000);

                               vc.view.layer.cornerRadius = 10; // this value vary as per your desire
                               vc.view.clipsToBounds = YES;

viewcontroller不是全屏的,所以还是可以看到之前的。我希望能够看到它,但将其锁定。就像你用ios facebook分享的时候,你看到了背景,但是变暗了,无法与之互动。我该怎么做?

最佳答案

我认为问题在于您使用 -presentModalViewController:animated: 来显示它。使用该方法带有一些关于您托管的 View Controller 的假设;它做出的假设之一(至少在 iPhone 类型的设备上)是 View Controller 占据整个屏幕并且是不透明的。

要解决这个问题,请尝试手动将模态视图 Controller 的 View 添加到当前 View Controller 的 View 中。您需要设置 View Controller 层次结构以匹配 View 层次结构,因此您的代码将如下所示:

[self addChildViewController:vc];
[self.view addSubview:vc.view];

您需要调整传入 View 的框架以将其定位在其新的父 View 中,但这应该会给您更多的自由。

关于ios - UIViewController透明背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13729501/

相关文章:

ios - NSArray 从其他数组添加对象

ios - TableViewCell 中的 UITextField 没有出现

ios - 如何让openfl在ios模拟器中运行

iphone - NSRegularExpression 用于从字符串中检索数字

android - Android Studio 有类似xcode 的autolayout 的功能吗?

iphone - 原型(prototype)单元不同于动态创建的单元

xcode - UIAlertController 和堆叠式 UIAlert 按钮

ios - 推送到另一个 ViewController

ios - 从 UITableViewCell 中的 UISwitch 更新核心数据

ios - iOS模拟器:从终端终止所有应用