【发布时间】:2012-05-31 23:29:39
【问题描述】:
我正在创建一个 iOS 应用程序。它在导航控制器中运行。在我最近构建的视图中,UITextViews 和 UIImageView 一直在错误的坐标处显示不正确。我相信这可能是由于UINavigationBar。
当我在 Interface Builder 中设置视图以镜像该视图时,它实际上
错误地显示视图。我再次假设这是由于UINavigationBar。我设法通过更改 Interface Builder 坐标来“修复”这个问题,直到它正确显示。这是 Interface Builder 现在的样子:
我希望视图可以在两种设备方向(纵向和横向)下工作。视图中的对象不容易被告知旋转,所以我以编程方式定位视图。代码如下:
-(void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {
if (orientation == UIInterfaceOrientationPortrait) {
appInfo.frame = CGRectMake(20, 19, 280, 90);
updateInfo.frame = CGRectMake(20, 117, 280, 86);
authorInfo.frame = CGRectMake(20, 229, 172, 200);
authorImage.frame = CGRectMake(190, 274, 110, 110);
}
else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
appInfo.frame = CGRectMake(11, 44, 199, 124);
updateInfo.frame = CGRectMake(218, 53, 242, 124);
authorInfo.frame = CGRectMake(11, 180, 340, 90);
authorImage.frame = CGRectMake(350, 170, 110, 110);
}
}
-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self adjustViewsForOrientation:toInterfaceOrientation];
}
-(void) viewWillAppear:(BOOL)animated {
[self adjustViewsForOrientation:self.interfaceOrientation];
[super viewWillAppear:animated];
}
这是我的主要问题: 当视图旋转到横向时,对象不能直接定位。它们不遵循旋转期间要调用的坐标中描述的内容。
旋转回纵向时也会出现此问题:
我该如何解决这个问题?提前谢谢您。
【问题讨论】:
-
您是否为此视图启用了任何自动布局?您可能是框架更改导致自动布局变得混乱。
-
不,我已经关闭了所有这些,假设您指的是 Interface Builder 中的方向更改设置
-
不,我怀疑他的意思是 IB 中的自动调整大小设置。
-
我确实知道要关闭自动调整大小。我的错误是将它们全部关闭。当我将它调整到左上角时,它起作用了。在我的开发过程中出现了相当愚蠢的错误,但非常感谢。
标签: objective-c ios cocoa-touch uinavigationbar uiinterfaceorientation