DetailView中的ipad SplitView方向

时间:2010-05-13 10:09:46

标签: ipad orientation uisplitviewcontroller

我在splitview应用程序的DetailView.m中使用此代码。现在,只有在旋转设备时才会发生方向更改。启动应用程序时不会进行检测。我也得到了这个警告

警告:'RootViewController'可能无法响应'-adjustViewsForOrientation:'

启动应用时,我需要做什么更改才能让应用调整方向代码。

> - (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
> duration:(NSTimeInterval)duration {
>     [self adjustViewsForOrientation:toInterfaceOrientation];
> }
> 
> - (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation
> {
>     if (orientation == UIInterfaceOrientationLandscapeLeft ||
> orientation ==
> UIInterfaceOrientationLandscapeRight)
> {
>         detailDescriptionLabel.center = CGPointMake(235.0f, 42.0f);
>         bigthumbImageView.center = CGPointMake(355.0f, 70.0f);
>         
>     }
>     else if (orientation == UIInterfaceOrientationPortrait ||
> orientation ==
> UIInterfaceOrientationPortraitUpsideDown)
> {
>         detailDescriptionLabel.center = CGPointMake(160.0f, 52.0f);
>         bigthumbImageView.center = CGPointMake(275.0f, 80.0f);
>         
>     } }

2 个答案:

答案 0 :(得分:1)

您需要在RootViewController.h中声明您的方法,如下所示:

- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation;

否则你会得到警告。要确保在应用程序启动时您的视图旋转,请在applicationDidFinishLaunching方法中为AppDelegate类中的adjustViewsForOrientation添加一个调用。

答案 1 :(得分:1)

要删除警告,请在-adjustViewsForOrientation:之前移动-willRotateToInterfaceOrientation:…的定义。

只有在界面旋转时才会调用-willRotateToInterfaceOrientation:…方法。当应用程序首次启动时,界面不会旋转(它遵循初始方向),因此不会生成此调用。你必须手动调用它,例如在-viewDidLoad

-(void)viewDidLoad {
   [self adjustViewsForOrientation:self.interfaceOrientation];
}
相关问题