关于UIView定位的问题

时间:2011-06-28 18:03:36

标签: iphone objective-c

我有两个viewController,A和B.

我希望这个应用程序仅用于Landscape,所以在A和B中我覆盖

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}

有两种方法可以初始化B,并将B的视图添加为A

的子视图

1

在A的viewDidLoad中,我通过init方法得到了B的对象。

B *bController = [[B alloc] init];
b.view.backgroundColor = [UIColor redColor];
[self.view addSubview:b.view];

2

在A的viewDidLoad中,我通过initWithNib方法获取B的对象。 在B的Nib文件中。我将视图的方向更改为LandScape,并将视图的大小更改为(480,300)

当我在B的viewDidLoad方法中输出B视图的帧时,得到了不同的结果。

方法1 ”的输出为(320,460),但设备已旋转为横向并且视图已满屏幕。

method2 ”的输出为(480,300)。这只是出于我的预期。

为什么method1的输出不是(480,300)而是(320,460)?

谢谢!

1 个答案:

答案 0 :(得分:0)

更改subView的autoSizing属性,即它。