gpt4 book ai didi

ios - 在横向模式下添加 UIView

转载 作者:行者123 更新时间:2023-12-01 19:00:48 24 4
gpt4 key购买 nike

我需要在我的 iOS 中添加广告功能应用程序。广告屏幕会在一段时间后出现。我的整体仅处于横向模式。当我尝试在当前 View 上添加 View 时,它会以纵向模式而不是横向模式显示 View 。我已经设置了 View 框架,即 CGSizeMake(0,0, 568, 320)

  time = [NSTimer scheduledTimerWithTimeInterval:2.0f 
target:self
selector:@selector(showfirstad)
userInfo:nil
repeats:YES];
-(void)showfirstad {
[[[[UIApplication sharedApplication] windows] lastObject] addSubview:firstad];
}

看起来像这样 subview appears in portrait mode .

最佳答案

_window = [UIApplication sharedApplication].keyWindow;
if (!_window) _window = [[UIApplication sharedApplication].windows objectAtIndex:0];

UIInterfaceOrientation orientation = self.window.rootViewController.interfaceOrientation;
// Set appropriate view frame (it won't be autosized by addSubview:)
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];

if (UIInterfaceOrientationIsLandscape(orientation))
{
// Need to flip the X-Y coordinates for landscape
self.view_login.frame = CGRectMake(appFrame.origin.y, appFrame.origin.x, appFrame.size.height, appFrame.size.width+20);
else
{
self.view_login.frame = appFrame;
}


[[[_window subviews] objectAtIndex:0] addSubview:self.view_login];

关于ios - 在横向模式下添加 UIView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23077886/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com