簡體   English   中英

單班iPhone定位問題

[英]iPhone orientation issue in single class

我對class1,class2和class3有4個類(class1,class2,class3和class4),我具有所有模式支持(橫向和縱向)。 但是對於第4課,我只需要肖像支持。 這里的問題是,當我在橫向模式下加載class4時,其在橫向視圖中的顯示視圖;一次將class4旋轉到人像模式時,它不會再次旋轉至橫向。 我希望class4僅在縱向模式下加載,而我在縱向或橫向模式下加載class 4。

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

請讓我知道,如何進行

似乎您需要做的就是對除縱向以外的所有內容返回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起已棄用。 如果您關心應用程序的未來生存能力,則可能需要考慮采取其他措施。

嘗試這個

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM