iOS - 具有透明度的 presentViewController

标签 ios uiviewcontroller

我想半透明地全屏显示一个 View Controller ,这样我仍然可以看到它下面的 View 。下面的代码展示了新的 View Controller ,但它取代了当前的 View Controller 。保持原始 View Controller 可见的最佳方法是什么?新 View Controller 的 View 将具有半透明的黑色背景。

NewViewController* newVC = [[NSClassFromString(@"NewViewController") alloc] initWithNibName:deviceNib bundle:nil];
newVC.modalPresentationStyle = UIModalPresentationFullScreen;
newVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;


[self presentViewController:newVC animated:YES completion:NULL];

最佳答案

呈现半透明 View ,而不是 View Controller 。

mySemiTransparentView.alpha = 0.0f;
[self.view addSubview:mySemiTransparentView];

mySemiTransparentView 是您的全屏 View 。您可以将其设置为动画:

[UIView beginAnimations:@"fadeIn" context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView setAnimationDuration:0.4f];
mySemiTransparentView.alpha = 0.5f;
[UIView commitAnimations];

关于iOS - 具有透明度的 presentViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11890205/

相关文章:

iphone - StackScrollView 与委托(delegate) ID MBProgressHUD 的问题

xcode - iOS sdk,从无符号字符数组渲染图像,CGBitmapContextCreate 返回 NULL

ios - Mapbox Geocoding API iOS 是否对大片水域(海洋)进行反向地理编码?

android - 当我们进行 ionic 状态恢复、保存、清除和重置时,实际发生了什么?

iphone - "Pushing the same view controller instance more than once is not supported"异常

objective-c - 如何将某些 View 的自动旋转限制为单一方向,同时允许其他 View 的所有方向?

iphone - 类图中的协议(protocol)/框架

ios - 如何正确使用 AVPlayer 使其在播放视频前不显示白屏?

iphone - 如何将 NSString 发送到另一个 View Controller

swift - 如何使用 Swift 循环访问 UIViewController 中的 View 导出?