1

我有一个简单的 IPAD 结构,其中包含来自 viewController 的视图的 AppDelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    ClockVC *clockVC = [[ClockVC alloc]init];
    clockVC.view.frame = CGRectMake(100, 100, clockVC.view.bounds.size.width, clockVC.view.bounds.size.height);

    [self.window addSubview:clockVC.view];
    [self.window makeKeyAndVisible];

    return YES;
}

clockVC 有一个由这段代码定义的 viewDidLoad :

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.autoresizingMask = UIViewAutoresizingNone;
    self.view.autoresizesSubviews = UIViewAutoresizingNone;
}

clockVC 的边界由 IB 定义并在 application:didFinishLaunching... 中覆盖。宽度和高度分别为 200 和 150。

ClockVC 实现一步自动旋转的方法:/

/ Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
}

-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{  
     [UIView animateWithDuration:0.5 
                     animations:^{self.view.alpha = 0;}
     ];
}

-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{ 
    [UIView animateWithDuration:1 
                     animations:^{self.view.alpha = 1;}
     ];
}

在第一次加载时,页面被正确查看并且clockVC 视图就位。当我旋转clockVC视图(其autoResizeMask设置为UIViewAutoresizingNon)调整大小以占据整个屏幕。

为什么 ??我想保持初始大小。

这里是我的问题的截图。旋转前: 在此处输入图像描述

旋转后: 在此处输入图像描述

4

1 回答 1

2

不要为此使用根视图,而是将子视图添加到视图控制器的视图中。UIViewControllers通常设计为填充其容器的整个空间(在这种情况下为窗口)。

例如,如果您将 a 添加UIViewController到 a UINavigationController,导航控制器将负责根据导航控制器的布局(导航栏是否可见等)来调整视图控制器的视图大小。我不确定 UIWindow 的行为究竟如何(我认为这不是很清楚的记录),但在 SDK 中的很多地方,视图控制器的父级负责其子级的定位和大小(UIPopoverController, UITabBarControlleret.al. )。

于 2011-04-27T13:53:32.227 回答