2012-07-31 35 views
0

我有一个ipad要求在横向和纵向显示内容..所以我已经完成了代码,并在每个方向完成控制的位置。它工作正常..我的代码是iphone sdk中的设备方向

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

上面的代码适合我,我得到了alla控制器在corect postions ..这是我的probm ,,我必须设置一个计时器来显示全屏,我需要隐藏一些控制器在viewcontroller, ,我把计时器设置为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); 

    } 
    } 

它工作正常,但定时器启动后,然后我chnage设备的方向,我只得到- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { function.i需要在时间function.how arrangmnts解决此问题。

在此先感谢。

}

回答

1

你应该可以在-shouldAutorotateToInterfaceOrientation:做这项工作。该方法仅仅是为了确定你的UI是否应该旋转(并且很快会被新系统取代)。你应该使用这些方法来反应你的UI布局,以实际旋转:

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

请参阅UIViewController docs更多关于这些。

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

+0

thankis for reply.how我可以使用这些方法吗?以及哪些代码会放到这些方法中。感谢 – stackiphone 2012-07-31 14:16:44

+0

它的工作我把这个 - didRotateFromInterfaceOrientation:方法,并将计时器方法的方向代码放到此方法中,并且它会启动。 – stackiphone 2012-07-31 14:27:40