2010-05-13 39 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