Ios 如何加载具有透明背景色的UIViewController?
如何加载具有透明背景色的UIViewController?使以前的视图控制器可见。 我尝试过用下面的方法创建自定义视图,但它不起作用Ios 如何加载具有透明背景色的UIViewController?,ios,objective-c,Ios,Objective C,如何加载具有透明背景色的UIViewController?使以前的视图控制器可见。 我尝试过用下面的方法创建自定义视图,但它不起作用 - (void)drawRect:(CGRect)rect { // Drawing code CGContextRef ctx = UIGraphicsGetCurrentContext(); CGContextSaveGState(ctx); { CGColorRef colorRef=[UIColor clea
- (void)drawRect:(CGRect)rect
{
// Drawing code
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSaveGState(ctx);
{
CGColorRef colorRef=[UIColor clearColor].CGColor;
CGContextSetFillColorWithColor(ctx, colorRef);
// CGColorRelease(colorRef);
CGContextFillRect(ctx, rect);
}
CGContextRestoreGState(ctx);
}
任何帮助都是值得的 可以通过添加子视图来实现这一点
//Get your screen size
CGRect screenBounds = [[UIScreen mainScreen] bounds];
//Create the transparent view of the same size
UIView* transparentView = [[UIView alloc] initWithFrame:screenBounds];
// change the background color to black and the opacity to 0.5 as this will make it look transparent
transparentView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
// add this new view to your main view
[self.view addSubview:transparentView];
然后在此视图中,您可以添加所有UI元素。这将使它看起来像一个透明的玻璃是放在旧的看法
完成后,您只需从超级视图中删除
[transprentView removeFromSuperview];
编辑:
或者你可以这样做
希望有帮助,
Julian使视图控制器的视图透明
viewController.view.backgroundColor=[UIColor clearColor]代码>
但是,它并不能帮助您在所有情况下看到视图控制器背后的内容。例如,如果您的控制器位于导航控制器中,则不会。
在这种情况下-在将新控制器推到顶部之前,使用创建快照视图,并将其用作顶部控制器所有内容下的层
像
你根本不应该使用drawRect。UIView有一个backgroundColor属性,您可以将其设置为[UIColor clearColor]
UIView有一个默认为“是”的不透明属性。尝试设置为否
UIView *backgroundView = [navVC.topViewController.view snapshotViewAfterScreenUpdates:NO];
[nextVC.view insertSubview:backgroundView atIndex:0];
[navVC psuhViewController:nextVC animated:YES];