2011-09-02 66 views
0

我正在創建一個支持所有方向的應用程序。
我在這裏使用navigationController。
的方向我使用這個代碼帶導航後退按鈕的自動旋轉

- (void)willAnimateRotationToInterfaceOrientation: 
(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration { 

if (interfaceOrientation == UIInterfaceOrientationPortrait 
    || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
{ 
    category1.frame = CGRectMake(54, 68, 190, 174); 
    category2.frame = CGRectMake(291, 68, 190, 174); 
    category3.frame = CGRectMake(525, 68, 190, 174); 
    category4.frame = CGRectMake(54, 296, 190, 174); 
    category5.frame = CGRectMake(291, 296, 190, 174); 
    category6.frame = CGRectMake(525, 296, 190, 174); 
    category7.frame = CGRectMake(54, 527, 190, 174); 
    category8.frame = CGRectMake(291, 527, 190, 174); 
    category9.frame = CGRectMake(525, 527, 190, 174); 
    category10.frame = CGRectMake(291, 757, 190, 174); 
    extra1.frame = CGRectMake(80, 781, 138, 125); 
    extra2.frame = CGRectMake(551, 781, 138, 125); 

} 
else 
{ 
    category1.frame = CGRectMake(61, 50, 190, 174); 
    category2.frame = CGRectMake(298, 50, 190, 174); 
    category3.frame = CGRectMake(537, 50, 190, 174); 
    category4.frame = CGRectMake(774, 50, 190, 174); 
    category5.frame = CGRectMake(61, 278, 190, 174); 
    category6.frame = CGRectMake(298, 278, 190, 174); 
    category7.frame = CGRectMake(537, 278, 190, 174); 
    category8.frame = CGRectMake(774, 278, 190, 174); 
    category9.frame = CGRectMake(298, 509, 190, 174); 
    category10.frame = CGRectMake(537, 509, 190, 174); 
    extra1.frame = CGRectMake(80, 533, 120, 125); 
    extra2.frame = CGRectMake(800, 533, 120, 125); 

} 

} 

它完美地在這一觀點。當我標籤按鈕它去secondviewcontroller我顯示tableview。
但是,如果我通過導航後退按鈕返回第一個視圖,則方向不會完美顯示。
以上代碼不適用於導航後退按鈕。

我應該爲這個問題做些什麼?
任何建議?

預先感謝您。

編輯:

我已刪除了我上面的功能從的firstView和代碼複製到這個功能。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    if (interfaceOrientation == UIInterfaceOrientationPortrait 
    || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) 
{ 
    category1.frame = CGRectMake(54, 68, 190, 174); 
    category2.frame = CGRectMake(291, 68, 190, 174); 
    category3.frame = CGRectMake(525, 68, 190, 174); 
    category4.frame = CGRectMake(54, 296, 190, 174); 
    category5.frame = CGRectMake(291, 296, 190, 174); 
    category6.frame = CGRectMake(525, 296, 190, 174); 
    category7.frame = CGRectMake(54, 527, 190, 174); 
    category8.frame = CGRectMake(291, 527, 190, 174); 
    category9.frame = CGRectMake(525, 527, 190, 174); 
    category10.frame = CGRectMake(291, 757, 190, 174); 
    extra1.frame = CGRectMake(80, 781, 138, 125); 
    extra2.frame = CGRectMake(551, 781, 138, 125); 

} 
else 
{ 
    category1.frame = CGRectMake(61, 50, 190, 174); 
    category2.frame = CGRectMake(298, 50, 190, 174); 
    category3.frame = CGRectMake(537, 50, 190, 174); 
    category4.frame = CGRectMake(774, 50, 190, 174); 
    category5.frame = CGRectMake(61, 278, 190, 174); 
    category6.frame = CGRectMake(298, 278, 190, 174); 
    category7.frame = CGRectMake(537, 278, 190, 174); 
    category8.frame = CGRectMake(774, 278, 190, 174); 
    category9.frame = CGRectMake(298, 509, 190, 174); 
    category10.frame = CGRectMake(537, 509, 190, 174); 
    extra1.frame = CGRectMake(80, 533, 120, 125); 
    extra2.frame = CGRectMake(800, 533, 120, 125); 

} 

    return YES; 
} 
在我的第二個視圖控制器

我做

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 

    return YES; 
} 

當我回去的firstView通過點擊導航後退按鈕else條件(風景模式)工作正常,但我不知道如果條件爲(Portraitmode),爲什麼它不與一起使用。

回答

1

在下面的函數中寫下所有的代碼。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
     //set all the frames according to the current interface orientation 
     return YES; 
} 

新的編輯:

寫這個方法到您的detailviewcontroller.m文件

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
    { 
     UIViewController *controller = [self.navigationController.viewControllers objectAtIndex:0]; 
     [controller shouldAutorotateToInterfaceOrientation:interfaceOrientation]; 

     return YES; 
    } 
+0

確定..我已經嘗試過了..但它不工作.. – iUser

+0

那麼它應該工作。當你回到這個viewController時,它是對這種方法的迴應嗎? – mayuur

+0

從此ViewController的nib關閉AutoResize子視圖。 – mayuur