0

クラス 1、クラス 2、クラス 3 には 4 つのクラス (クラス 1、クラス 2、クラス 3、クラス 4) があり、すべてのモードがサポートされています (ランドスケープとポートレート)。しかし、クラス 4 の場合、ポートレートのサポートのみが必要です。ここでの問題は、class4 をランドスケープ モードでロードすると、ビューがランドスケープで表示され、class4 をポートレート モードに一度回転すると、再びランドスケープに回転しないことです。クラス 4 をポートレートのみの天候でロードしたいのですが、クラス 4 をポートレートまたはランドスケープ モードでロードします。

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

進め方を教えてください

4

2 に答える 2

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

ところで、の公開ドキュメントによると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 に答える