【问题标题】:Device Orientation in iphone sdkiphone sdk中的设备方向
【发布时间】:2016-01-31 03:42:57
【问题描述】:

我需要 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;
}

上面的代码对我来说很好,我得到了正确位置的所有控制器..这是我的问题,我必须设置一个计时器以显示全屏,我需要在视图控制器中隐藏一些控制器,我已将计时器设置为 3 秒,3 秒后它隐藏了一些控件并安排视图控制器中的其他控制器以显示完整的屏幕。它对我来说也很好用。我的代码是

- (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 {函数中的排列。我需要时间函数中的排列。如何解决这个问题。

提前致谢。

}

【问题讨论】:

    标签: iphone ios device-orientation


    【解决方案1】:

    你不应该-shouldAutorotateToInterfaceOrientation: 做这项工作。该方法只是确定您的 UI 是否应该旋转(并且很快会被新系统取代)。您应该使用这些方法来布置您的 UI 以响应实际的旋转:

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

    请参阅UIViewController docs 了解更多信息。

    在 iOS 5 上,-viewWillLayoutSubviews 可能是另一个不错的选择。 (即使您的控制器的视图当前不可见,它也会被调用。)

    【讨论】:

    • 感谢您的回复。我该如何使用这些方法?我将在这些方法中添加哪些代码。谢谢
    • 它的工作我把这个 -didRotateFromInterfaceOrientation: 方法和定时器方法的方向代码放到这个方法和它 woks.thanks
    猜你喜欢
    • 1970-01-01
    • 2011-09-27
    • 2011-06-23
    • 1970-01-01
    • 1970-01-01
    • 2011-04-16
    • 1970-01-01
    • 2011-10-13
    • 2011-06-14
    相关资源
    最近更新 更多