2012-07-31 34 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