单一类中的iPhone方向问题

时间:2013-07-01 05:58:13

标签: iphone ios screen orientation screen-orientation

我有4个类(class1,class2,class3和class4)用于class1,class2和amp; class3我支持所有模式(Landscape& Portrait)。但是对于4级我只需要Portrait支持。这里的问题是当我在横向模式下加载class4时它在横向显示视图,当我将class4旋转到Portrait模式一次时,它不再旋转到横向。我希望class4以纵向加载天气我来到纵向或横向模式加载4级。

i tried this
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
   if (interfaceOrientation != UIInterfaceOrientationPortrait)
  {
     return NO;
  }
}

请告诉我,如何继续

2 个答案:

答案 0 :(得分:0)

似乎所有你需要做的就是为纵向方向的所有内容返回YES。

怎么样:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // b.t.w., there is also an upside down portrait constant
    // which is UIInterfaceOrientationPortraitUpsideDown
    if (interfaceOrientation != UIInterfaceOrientationPortrait)
    {
       return NO;
    }
    return YES;
}

B.T.W。,根据shouldAutorotateToInterfaceOrientation:的公开文档,从iOS 6.0开始,该API已被弃用。如果您关心应用程序未来的生存能力,您可能需要考虑做一些不同的事情。

答案 1 :(得分:0)

试试这个

    -(void)orientationChanged:(NSNotification *)object{
        NSLog(@"orientation change");
        UIDeviceOrientation deviceOrientation = [[object object] orientation];
        if(deviceOrientation == UIInterfaceOrientationLandscapeLeft ||deviceOrientation == UIInterfaceOrientationLandscapeRight)
        {
            Bg.image=[UIImage imageNamed:@"splashBgL.png"]; ///Lendscape Background
            Bg.frame=CGRectMake(0, 0, 480, 320);
            self.view.frame=CGRectMake(0, 0, 480, 320);
        } 
        else{
            Bg.image=[UIImage imageNamed:@"splashBg.png"];///Protrait Background
            Bg.frame=CGRectMake(0, 0, 320, 480);
        }
    }

    -(void)landscapeLeftOrientation{
          CGRect contentRect = CGRectMake(0, 0, 480, 320);;
          self.view.bounds = contentRect;
    }

    -(void)landscapeRightOrientation{
           CGRect contentRect = CGRectMake(0, 0, 480, 320);
           self.view.bounds = contentRect;
    }


    - (void)viewDidLoad
    {
         [super viewDidLoad];
         [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
         [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:)name:@"UIDeviceOrientationDidChangeNotification" object:nil];
    }

    -(void)viewWillAppear:(BOOL)animated {
        [super viewWillAppear:animated];
            [self landscapeLeftOrientation];
    }