在我的应用程序中,我将在主窗口中创建一些UIView,并且UIView使用自动调整大小,但这不支持

如果设备模式为纵向,则可以正常工作
但是devicemode是横向登录视图,以减号获得x位置。

在窗口上添加视图

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


图片:


提前致谢..

最佳答案

_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+40);
}
else
{
    self.view_login.frame = appFrame;
}


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

关于ios - iPhone SDK中 subview appdelegate的自动调整大小问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23005335/

10-14 21:18