2013-03-02 81 views
0

如何在iphone和ipad的ios6中爲不同的背景圖像設置不同的方向?現在,我設置圖像BG垂直如下,基於方向的UIView背景圖像

- (void)viewDidLoad 
{ 
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"ihome.png"]]; 
[super viewDidLoad]; 
} 

我厭倦了以下編碼它甚至不是裏面的代碼會

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
{ 
if (toInterfaceOrientation==UIInterfaceOrientationMaskLandscapeRight) 
{ 
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"lhomescreen.png"]]; 
} 
if (toInterfaceOrientation==UIInterfaceOrientationMaskLandscapeLeft) 
{ 
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"lhomescreen.png"]]; 
} 
if (toInterfaceOrientation==UIInterfaceOrientationMaskPortrait) 
{ 
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"ihome.png"]]; 
} 

return YES; 

} 

請幫我整理出來

編輯

- (BOOL)shouldAutorotate 
{ 
return YES; 
} 

- (NSUInteger)supportedInterfaceOrientations 
    { 
// return (UIInterfaceOrientationMaskAllButUpsideDown); 
return (UIInterfaceOrientationMaskAll); 
} 

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 

if (toInterfaceOrientation==UIInterfaceOrientationMaskLandscapeRight) 

      self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"lhomescreen.png"]]; 

if (toInterfaceOrientation==UIInterfaceOrientationMaskLandscapeLeft) 

     self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"lhomescreen.png"]]; 

if (toInterfaceOrientation==UIInterfaceOrientationMaskPortrait) 

     self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"ihome.png"]]; 


    // return YES; 
} 

回答

0

來自apple文檔:

shouldAutorotateToInterfaceOrientation: 返回一個布爾值,指示視圖控制器是否支持指定的方向。 (不推薦使用iOS中6.0。重寫supportedInterfaceOrientationspreferredInterfaceOrientationForPresentation方法來代替。)」

+0

我更新了我的問題。我試過,但它亙古不變的在我的代碼 – Fazil 2013-03-02 13:52:21

+0

更新我的答案,PLZ再試一次修復任何概率。 – 2013-03-03 09:30:13