2010-12-22 60 views
1

我開始使用具有2個視圖(第一視圖控制器和第二視圖控制器)的tabbar應用程序。第二個視圖控制器沒有背景圖像,但第一個視圖控制器沒有。iPad定位問題

我有兩個圖像一個爲protrait和一個爲景觀。我想要做的就是在方向改變時加載背景圖片。我想支持所有的方向。

這裏是我的viewDidLoad方法

-(void)viewDidLoad 
{ 
    imgview=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bgportrait.png"]]; 
    [imgview setFrame:CGRectMake(0, 0, 768, 1024)]; 
    [self.view addSubview:imgview]; 
    [self.view sendSubviewToBack:imgview]; 
    [imgview release]; 
} 

(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {的NSLog(@ 「在shouldrotate」); 返回YES; }

(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    if (toInterfaceOrientation == (UIInterfaceOrientationPortrait || UIInterfaceOrientationPortraitUpsideDown)) 
{ 
    NSLog(@"in portrait"); 
} 
else if (toInterfaceOrientation == (UIInterfaceOrientationLandscapeLeft || UIInterfaceOrientationLandscapeRight)) 
{ 
    NSLog(@"in landscape"); 
} 

} 
在willRotateToInterfaceOrientation

它從來沒有進入任何一個如果循環和它不打印日誌,我不知道爲什麼它的方向不匹配其一。我只是想爲firstviewcontroller設置適當的backgroundimage。我知道這應該很簡單,但我無法做到。

+0

請格式化你的代碼。在編輯您的問題時,編輯器上方會有一個符號,用於適當地設置代碼的格式。 – darioo 2010-12-22 13:54:01

回答

2

檢查你的病情是這樣

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    if(toInterfaceOrientation==UIInterfaceOrientationPortrait || 
     toInterfaceOrientation==UIInterfaceOrientationPortraitUpsideDown) 
    { 
     NSLog(@"in portrait"); 
    } 
    else 
    { 
     NSLog(@"in landscape"); 
    } 
} 
+0

是的,現在它進入if循環。現在我做了這個 – Rajashekar 2010-12-22 14:26:55