0

我有 4 个类(class1、class2、class3 和 class4)用于 class1、class2 和 class3 我支持所有模式(风景和肖像)。但是对于第 4 类,我只需要肖像支持。这里的问题是,当我在横向模式下加载 class4 时,它以横向显示视图,当我将 class4 旋转到纵向模式一次时,它不会再次旋转到横向。我希望 class4 仅以纵向加载,天气我以纵向或横向模式加载 class 4。

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

请告诉我,如何进行

4

2 回答 2

0

似乎您需要做的就是对除纵向以外的所有内容返回“是”。

怎么样:

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

顺便说一句,根据 的公共文档shouldAutorotateToInterfaceOrientation:,此 API 自 iOS 6.0 起已弃用。如果您关心应用在未来的生存能力,您可能需要考虑做一些不同的事情。

于 2013-07-01T06:12:26.230 回答
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];
    }
于 2013-07-01T06:20:23.003 回答