一个简单的iphone程序,由项目模板View-based Application生成,有几个按钮,我添加了以下代码:
- (void) showInfo: (UIView *) view {
NSLog(@"view bounds %6.2f %6.2f %6.2f %6.2f", view.bounds.origin.x, view.bounds.origin.y, view.bounds.size.width, view.bounds.size.height);
NSLog(@"view frame %6.2f %6.2f %6.2f %6.2f", view.frame.origin.x, view.frame.origin.y, view.frame.size.width, view.frame.size.height);
NSLog(@"view center %6.2f %6.2f", view.center.x, view.center.y);
}
- (BOOL)shouldAutorotateToInterfaceOrientation: UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void)willRotateToInterfaceOrientation: (UIInterfaceOrientation) toInterfaceOrientation duration:(NSTimeInterval) duration {
switch(toInterfaceOrientation) {
case UIInterfaceOrientationPortrait:
[self showInfo: self.view];
break;
case UIInterfaceOrientationLandscapeLeft:
[self showInfo: self.view];
break;
case UIInterfaceOrientationLandscapeRight:
[self showInfo: self.view];
break;
}
}
- (void) didRotateFromInterfaceOrientation: (UIInterfaceOrientation) fromInterfaceOrientation {
switch(fromInterfaceOrientation) {
case UIInterfaceOrientationPortrait:
[self showInfo: self.view];
break;
case UIInterfaceOrientationLandscapeLeft:
[self showInfo: self.view];
break;
case UIInterfaceOrientationLandscapeRight:
[self showInfo: self.view];
break;
}
}
以纵向模式启动模拟器,然后向右更改为横向模式。我可以得到:
视图边界 0.00 0.00 320.00 460.00
视图框架 0.00 20.00 320.00 460.00
查看中心 160.00 250.00
在纵向模式下,视图尺寸为 320x460,由于状态栏的原因,其原点为 (0,20)。
视图边界 0.00 0.00 480.00 300.00
视图框架 0.00 0.00 300.00 480.00
查看中心 150.00 240.00
在横向右侧,边界的大小更改为 480x300,但框架的原点为 (0, 0)。并且框架的大小与边界不同。
在我的脑海中,我想象这些坐标如下图所示:
我的问题是:在横向右侧,框架的原点似乎指向一个位置,而边界的原点指向另一个位置。所以我认为在视图控制器的某个地方会发生一些旋转。它在哪里,有什么作用?
感谢您阅读这个又长又不太清楚的问题。 :)