【问题标题】:Orientation based UIView Background images基于方向的 UIView 背景图片
【发布时间】:2013-03-02 13:16:59
【问题描述】:

如何在 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;
 }

【问题讨论】:

    标签: iphone ipad ios6 uiinterfaceorientation


    【解决方案1】:

    来自苹果文档:

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

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

    【讨论】:

    • 我更新了我的问题。我试过了,但它没有修复我的代码中的任何问题
    猜你喜欢
    • 2012-04-17
    • 1970-01-01
    • 2011-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-20
    • 2020-10-16
    相关资源
    最近更新 更多