Jos*_*ane 20 iphone transparency objective-c uiviewcontroller
我想以模态方式添加一个透明背景的视图控制器,因此可以看到下面的父视图控制器.(这适用于iPhone,不适用于iPad.)
我试过这个:
TextFieldViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"TextFieldVC"];
vc.modalPresentationStyle = UIModalPresentationCurrentContext;
vc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self.navigationController presentViewController:vc animated:YES completion:^{}];
Run Code Online (Sandbox Code Playgroud)
没有运气,给视图控制器一个清晰的颜色背景.如果改变了什么,我的视图控制器就在故事板中.
or *_*ran 14
@Josh Kahane设置了视图控制器,它将在此处显示带有此代码的透明视图控制器,-ViewDidLoad
并确保将UIViewController
视图的Alpha通道设置为低于1.
码:
self.modalPresentationStyle = UIModalPresentationCurrentContext;
Run Code Online (Sandbox Code Playgroud)
小智 7
我一直在寻找解决方案.现在感谢iOS 8.他们推出了几个新的modalPresentationStyle.其中一个是UIModalPresentationOverCurrentContext.使用相同的方法来解决这个问题.
viewcontroller.modalPresentationStyle = UIModalPresentationOverCurrentContext;
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助.
为了完整性并使其保持最新,我还为Swift添加了解决方案:
或
viewController.modalPresentationStyle = .CurrentContext
Run Code Online (Sandbox Code Playgroud)
存在 - 一种表示风格,其中内容仅显示在呈现视图控制器的内容上.
要么
viewController.modalPresentationStyle = .OverCurrentContext
Run Code Online (Sandbox Code Playgroud)
being - 一种表示样式,其中内容仅显示在父视图控制器的内容上.演示文稿完成后,不会从视图层次结构中删除所显示内容下方的视图.因此,如果呈现的视图控制器没有用不透明的内容填充屏幕,则底层内容会显示出来.
取决于演示文稿的要求和环境.
虽然有很多步骤可以轻易忘记,但这是可能的.在与我自己努力工作4小时后,我想出了以下解决方案.
1 - 像创建其他任何一个一样创建一个View Controller.
头文件
#import "DDBaseViewController.h"
@interface DDHomeSearchLoadingViewController : UIViewController
@end
Run Code Online (Sandbox Code Playgroud)
实施文件
#import "DDHomeSearchLoadingViewController.h"
@interface DDHomeSearchLoadingViewController ()
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityMonitor;
@property (weak, nonatomic) IBOutlet UIView *modalView;
@end
@implementation DDHomeSearchLoadingViewController
#pragma mark - UIViewController lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
[self setupUI];
}
-(void) setupUI
{
[self makeRoundedCorner:self.modalView AndCornerRadius:6.0f];
[self.activityMonitor startAnimating];
}
-(void) makeRoundedCorner:(UIView*) view AndCornerRadius:(float) cornerRadius
{
[view.layer setCornerRadius:cornerRadius];
[view.layer setMasksToBounds:YES];
}
@end
Run Code Online (Sandbox Code Playgroud)
2 - 将容器视图背景颜色设置为ClearColor
3 - 添加一个UIView,它将呈现为叠加层
4 - 添加一个UIView,它将在叠加层UIView上显示为对话框
添加/移动它时,请确保它在叠加视图之外.出于某种原因,当您使用鼠标移动它时,它会自动添加到覆盖UIView.(说实话,这很烦人)
5 - 为您创建的视图设置故事板ID
6 - 最后在你不称之为的地方添加这段代码(假设它也是一个UiViewController)
DDHomeSearchLoadingViewController* ddHomeSearchLoadingViewController = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"DDHomeSearchLoadingViewController"];
self.navigationController.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:ddHomeSearchLoadingViewController animated:YES completion:nil];
Run Code Online (Sandbox Code Playgroud)
我希望它可以帮助你们
干杯
归档时间: |
|
查看次数: |
17447 次 |
最近记录: |