2010-05-13 61 views
1

我在splitview应用程序的DetailView.m中使用此代码。现在只有当设备旋转时才会发生方向更改。检测不会在应用程序启动时发生。我也得到这样的警告ipad SplitView方向详细查看

警告:“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); 
>   
>  } } 

回答

1

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

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

-(void)viewDidLoad { 
    [self adjustViewsForOrientation:self.interfaceOrientation]; 
} 
+0

虽然pheelicks的回答取消了警告,但这样做还是有效的。谢谢 – nishantcm 2010-05-14 10:29:23

1

您必须声明你的方法RootViewController.h,像这样:

- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation; 

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

+0

谢谢。这消除了警告。 – nishantcm 2010-05-14 10:28:42