2013-03-02 82 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