0

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

提前致谢。

}

4

1 回答 1

1

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

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

有关这些的更多信息,请参阅UIViewController文档

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

于 2012-07-31T14:09:22.113 回答