[英]How to add a fullscreen subview to the current UIWindow in objective c which will change according to the device orientation?
我想在当前呈现的viewcontroller上添加一个覆盖整个屏幕的临时视图,经过研究后发现我应该将该屏幕添加为当前UIWindow的子视图,我使用了以下代码,但是该视图并未覆盖整个屏幕屏幕。
`UIWindow* mainWindow = [[UIApplication sharedApplication] keyWindow];
//mainWindow.frame=self.view.frame;
_autoPlayViewBackground.frame=self.view.frame;
_autoPlayViewBackground.hidden=NO;
[mainWindow addSubview:_autoPlayViewBackground];`
这段代码提供了一个通向一面的窗口。任何帮助都将是一个很大的帮助。
尝试这个
_autoPlayViewBackground.frame=self.view.frame;
进入
_autoPlayViewBackground.view.frame = window.bounds; // or use window .frame
_autoPlayViewBackground.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
这个怎么样?
UIWindow* window = [UIApplication sharedApplication].keyWindow;
if (!window)
window = [[UIApplication sharedApplication].windows objectAtIndex:0];
[[[window subviews] objectAtIndex:0] addSubview:myView];
确保要显示的内容将添加到myView
UIView
中。 这是非常重要的一步。
请尝试给定的方法以全屏显示AutoPlayBgView
- (void) showAutoPlayBgViewInFullScreen
{
UIWindow* window = [[UIApplication sharedApplication] keyWindow];
// set frame of auto play bg view
_autoPlayViewBackground.frame = window.frame;
// add auto play bg view as subview in window
[window addSubview: _autoPlayViewBackground];
}
希望这段代码对您有所帮助。
请遵循以下模式:
CGRect rect = [[UIScreen mainScreen] bounds];
subView.frame = rect;
[parentView addSubview:subView];
希望这可以帮助!
要将全屏子视图添加到当前的UIWindow
您可以这样做。
UIView *viewBg=[[UIView alloc]initWithFrame:CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height)];
[viewBg setBackgroundColor:[UIColor colorWithRed:1/255.f green:1/255.f blue:1/255.f alpha:0.4]];
[self.view.window addSubview:viewBg];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.