【发布时间】:2011-12-27 01:15:29
【问题描述】:
我正在 iPad 上开发此应用程序。我的 MainWindow 包含一个拆分视图控制器,它加载 RootViewController 和 DetailViewController。
我有这张图片位于 DetailViewController 的右下角。
我的应用程序允许不同的方向,因此我希望图像针对不同的方向出现在不同的位置。
这是我在 DetailViewController 中的代码:
- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
myImage.frame = CGRectMake(183.0f, 257.0f, 548.0f, 447.0f);
}
else if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
myImage.frame = CGRectMake(244.0f, 518.0f, 548.0f, 447.0f);
}
}
当我启动我的应用程序并且我的 iPad 处于纵向时,图像将正确放置在右下角的 (X:244, Y:518) 处。 但是当我启动我的应用程序并且我的 iPad 处于横向时,图像将不会显示,我怀疑它仍然处于纵向位置。只有当我将 iPad 旋转到纵向,然后再转回横向时,图像才会出现在 (X:183, Y:257) 处,这是正确的。
我试图做的是将这些代码放在我的 DetailViewController 的“viewWillAppear”方法中:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if(self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
myImage.frame = CGRectMake(183.0f, 257.0f, 548.0f, 447.0f);
}
else if(self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
myImage.frame = CGRectMake(244.0f, 518.0f, 548.0f, 447.0f);
}
}
但是当我启动我的应用程序时,它仍然有同样的问题。
我该怎么做才能在我第一次横向启动我的应用程序时,将其正确放置在 (X:244, Y:518) ?
【问题讨论】:
标签: objective-c ios xcode ipad uiinterfaceorientation