一个简单的iPhone程序,由基于项目模板视图的应用程序生成,有几个按钮,我添加了以下代码:
—(void)showinfo:(uiview*)view{
nslog(@“视图边界%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(@“图幅%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(@“视图中心%6.2f%6.2f”,view.center.x,view.center.y);
}
-(bool)shouldAuto接口方向:ui接口方向)接口方向{
返回(接口定向!=uiInterfaceOrientationPortraiseUpsideDown);
}
-(无效)旋转界面方向:(uiInterfaceOrientation)到界面方向持续时间:(nsTimeInterval)持续时间{
开关(至界面方向){
案例uiInterfaceOrientationPortrait:
[自我展示信息:self.view];
断裂;
案例ui界面方向景观左:
[自我展示信息:self.view];
休息;
案例ui界面方向景观:
[自我展示信息:self.view];
断裂;
}
}
-(空)双旋转界面方向:(ui界面方向)从界面方向{
切换(从InterfaceOrientation){
案例uiInterfaceOrientationPortrait:
[自我展示信息:self.view];
断裂;
案例ui界面方向景观左:
[自我展示信息:self.view];
断裂;
案例ui界面方向景观:
[自我展示信息:self.view];
断裂;
}
}
< /代码>
启动纵向模拟器,切换到横向右侧。我可以得到:
视图边界0.00 0.00 320.00 460.00
镜框0.00 20.00 320.00 460.00
视图中心160.00 250.00
在Portrait中,视图的大小为320x460,它的原点是(0,20),因为状态栏。
视界0.00 0.00 480.00 300.00
镜框0.00 0.00 300.00 480.00
视图中心150.00 240.00
在Landscape Right中,bounds的大小更改为480x300,但是帧的原点是(0,0)。帧的大小与边界不同。
在我的头脑中,我想象这些坐标就像下图:


我的问题是:在景观右图中,框架的原点似乎指向一个位置,而边界的原点则指向另一个位置。所以我想在视图控制器的某个地方,会发生一些旋转。它在哪里,它做什么?
谢谢你读了这么长时间不太清楚的问题。))E:
- (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
在Portrait中,视图的大小是320x460,由于状态栏的原因,它的原点是(0,20)。
视界0.00 0.00 480.00 300.00
镜框0.00 0.00 300.00 480.00
视图中心150.00 240.00
在Landscape Right中,bounds的大小更改为480x300,但是帧的原点是(0,0)。帧的大小与边界不同。
在我的头脑中,我想象这些坐标如下图所示:


我的问题是:在景观右图中,框架的原点似乎指向一个位置,而边界的原点则指向另一个位置。所以我想在视图控制器的某个地方,会发生一些旋转。它在哪里,它做什么?
谢谢你读了这么长时间不太清楚的问题。:)