簡體   English   中英

iPhone SDK中的設備方向

[英]Device Orientation in iphone sdk

我對ipad有要求,可以同時顯示橫向和縱向內容。.所以我已經完成了代碼,並完成了各個方向上的控件位置。工作正常。.我的代碼是

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    if (interfaceOrientation == UIInterfaceOrientationLandscapeRight ||interfaceOrientation == UIInterfaceOrientationLandscapeLeft  ) {

        _viewContainer.frame = CGRectMake(342, 1, 681, 707);
        _viewtopic.frame = CGRectMake(1, 62, 343, 56);
        _viewpublicspeekingheaderleft.frame = CGRectMake(0, 6, 341, 58);
        _viewTableview.frame = CGRectMake(1, 118, 341, 590);
        _viewFooter.frame = CGRectMake(1, 716, 1024, 48);


  if (interfaceOrientation == UIInterfaceOrientationPortrait ||interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown  ) {

        _viewContainer.frame = CGRectMake(276, 1, 503, 946);
        _viewtopic.frame = CGRectMake(0, 58, 275, 50);
        _viewpublicspeekingheaderleft.frame = CGRectMake(0, 1, 275, 58);
        _viewTableview.frame = CGRectMake(1, 109, 274, 837);
        _viewFooter.frame = CGRectMake(1, 954, 767, 48);

    }

    return YES;
}

上面的代碼對我來說很好,我將所有控制器都放在了corect位置..這是我的問題,我必須設置一個計時器以顯示全屏,並且我需要在viewcontroller中隱藏一些控制器,我已經完成了計時器設置為3秒,然后3秒后,它隱藏了一些控件並在視圖控制器中安排了其他控件以顯示ful sceen。它對我來說也很好。

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Define the timer object

    NSTimer *timer;

   // Create the timer object

    timer = [NSTimer scheduledTimerWithTimeInterval:3.0 target:self 
                                           selector:@selector(updateorientation:) userInfo:nil repeats:NO];
}

- (void) updateorientation:(NSTimer *)incomingTimer
{

    _tableTopic.hidden =YES;
    _viewtopic.hidden =YES;
    _viewpublicspeekingheaderleft.hidden =YES;
    _viewTableview.hidden =YES;
    _imgpulbicspeakingabovethetableview.hidden =YES;
    _topiclabel.hidden =YES;
    _lblpublicspeekingleft.hidden =YES;


    UIInterfaceOrientation orientation =[[UIApplication sharedApplication] statusBarOrientation];
    if (orientation == UIDeviceOrientationPortrait || orientation == UIDeviceOrientationPortraitUpsideDown ) {
        NSLog(@"portrait");// only works after a rotation, not on loading app

        _imgMicimage.frame = CGRectMake(69, 130, 635, 216);
          _txtContentofTopic.frame = CGRectMake(69, 354, 635, 203);
          _viewContainer.frame = CGRectMake(0, 0, 768, 1024);


    }
    UIInterfaceOrientation orientationLandscape =[[UIApplication sharedApplication] statusBarOrientation];
    if (orientationLandscape == UIDeviceOrientationLandscapeLeft || orientationLandscape == UIDeviceOrientationLandscapeRight ) {
        NSLog(@"landscape");

        _imgMicimage.frame = CGRectMake(93, 113, 836, 239);
        _txtContentofTopic.frame = CGRectMake(93, 360, 836, 203);
        _viewContainer.frame = CGRectMake(0, 0, 1024, 768);

    }
    }

它工作正常,但是在計時器觸發后,然后我改變了設備的方向,我只在- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {應該AutorotateToInterfaceOrientation - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { function。解決這個。

提前致謝。

}

應該在-shouldAutorotateToInterfaceOrientation:進行這項工作。 該方法只是確定您的UI是否應該旋轉(不久將被新系統取代)。 您應該使用以下方法來布局UI以響應實際的輪換:

  • -willRotateToInterfaceOrientation:duration:
  • -willAnimateRotationToInterfaceOrientation:duration:
  • -didRotateFromInterfaceOrientation:

有關更多信息,請參閱UIViewController文檔

在iOS 5上, -viewWillLayoutSubviews可能是另一個不錯的選擇。 (即使當前不顯示控制器的視圖,也會調用它。)

暫無
暫無

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

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