2013-01-14 40 views
1

我目前正在使用具有「時間表」的IPhone應用程序。 肖像我希望它有一個定製的定期表視圖!當我在風景中使用IPhone時,我希望它可以更改爲更「時間表」 - 查看錶格和行。如何在肖像和風景中提供兩種不同的視圖?

可能嗎?

+0

它在兩個5.1和6.0 – SimonZ1

+0

工作你爲什麼要改變橫向視圖有何看法?只需啓用項目中的所有方向,它就會自動自動導向。如果我誤解了你的問題,請糾正我。 –

+0

我只希望時間表能夠在橫向上旋轉,而不是整個應用程序 – SimonZ1

回答

1

見蘋果文檔Creating an Alternate Landscape Interface

請務必閱讀文檔,但這裏仍是這個例子的實現代碼:

@implementation PortraitViewController 
- (void)awakeFromNib 
{ 
    isShowingLandscapeView = NO; 
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
    [[NSNotificationCenter defaultCenter] addObserver:self 
           selector:@selector(orientationChanged:) 
           name:UIDeviceOrientationDidChangeNotification 
           object:nil]; 
} 

- (void)orientationChanged:(NSNotification *)notification 
{ 
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation; 
    if (UIDeviceOrientationIsLandscape(deviceOrientation) && 
     !isShowingLandscapeView) 
    { 
     [self performSegueWithIdentifier:@"DisplayAlternateView" sender:self]; 
     isShowingLandscapeView = YES; 
    } 
    else if (UIDeviceOrientationIsPortrait(deviceOrientation) && 
      isShowingLandscapeView) 
    { 
     [self dismissViewControllerAnimated:YES completion:nil]; 
     isShowingLandscapeView = NO; 
    } 
} 
0

答案是是的,它通過下面的方法是可行的:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
if(UIInterfaceOrientationIsLandscape(toInterfaceOrientation)){ 
\\ your timetable customisation goes here 
    } 
} 

您還需要:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
    { 
     return YES; 
    } 
2

嘗試這個

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 


    [self adjustViewsForOrientation:toInterfaceOrientation]; 

} 

-(void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation 
{ 
    if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) 
    { 
     //write code for portrait mode 
    } 
    else if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) 
    { 
     //write code for landscape mode 


    } 
}