繁体   English   中英

基于方向的UIView背景图像

[英]Orientation based UIView Background images

如何在iPhone和iPad的ios6中为不同方向设置不同的背景图像? 现在我将图像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;
 }

从苹果文档:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM