0

如何在 ios6 中为 iphone 和 ipad 设置不同方向的不同背景图像?现在我将图像 bg 设置为垂直如下,

- (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;
 }
4

1 回答 1

0

来自苹果文档:

shouldAutorotateToInterfaceOrientation: 返回一个布尔值,指示视图控制器是否支持指定的方向。(在 iOS 6.0 中已弃用。覆盖supportedInterfaceOrientationsandpreferredInterfaceOrientationForPresentation方法。)”

- (BOOL)shouldAutorotate
{
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;
}
于 2013-03-02T13:44:52.017 回答