2011-02-11 60 views
0

我正在構建一個ap,其中需要從superView中移除當前視圖並加載另一個視圖。但是新加載的視圖向上移動。同樣,當第一個視圖再次加載時,它會完美加載。從第一個視圖翻轉時第二個視圖向上移動

任何人都可以建議一些東西來擺脫這個問題。

以下是我使用的視圖翻轉secondView

-(void) flipToBack 
{ 
CreateMessageViewController *oSecondView = [[CreateMessageViewController alloc] initWithNibName:@"CreateMessageViewController" bundle:nil]; 
[self setMsgViewController:oSecondView]; 
[oSecondView release]; 

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.8]; 
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:window cache:YES]; 

[viewController.view removeFromSuperview]; 
[tabBarController.view removeFromSuperview]; 
[self.window addSubview:[msgViewController view]]; 
[UIView commitAnimations]; 
} 

提前感謝的方法!

期待您的迴應。

感謝

回答

0

經過很長時間玩代碼和IB,我發現了錯誤。它被糾正爲

打開mainWindow.xib並添加庫中的UIViewController對象。將其類更改爲處理指定viewController的類,然後進行單擊。轉到屬性檢查器的屬性部分,併爲控制器設置相應的筆尖名稱,現在保存並退出IB。

和代碼更改

-(void) flipToBack 
{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.8]; 
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:window cache:YES]; 

    [viewController.view removeFromSuperview]; 
    [tabBarController.view removeFromSuperview]; 
    [self.window addSubview:[msgViewController view]]; 
    [UIView commitAnimations]; 
} 

感謝所有誰回答!

0

沒有太多我可以告訴大家不用看大圖。檢查IB中的幀,看看它們是否正確設置。 這是你的appDelegate的代碼嗎? viewController是否在他的視圖中顯示了一個工具欄?也許你的看法轉移了你的工具欄高度的確切像素?

+0

感謝您的回覆......但IB中的幀完全放置,移位不等於工具欄的高度。問題依然存在,即使沒有任何工具欄 – devsri 2011-02-16 10:19:43

+0

雅代碼是AppDelegate的一部分...... – devsri 2011-02-16 10:21:54

0

明白了。 這是由於IB設置發生的。所以在IB你的viewController有一個statusBar,你的視圖的高度爲460(對於iPhone)而不是480.20點是statusBar的高度。當轉換到第二個視圖時,其矩形爲{0,0,320,460},因此視圖位於應用程序的狀態欄後面,並且缺少底部的20個點。

要解決這個問題,你需要:

  1. 走進IB並設置CreateMessageViewController的一個狀態欄未指定。
  2. 進入視圖大小部分並將視圖的高度設置爲480(對於iPhone)。

現在您的CreateMessageViewController視圖將正常顯示。

相關問題