2014-03-19 71 views
0

我的應用程序顯示pdf頁面,在縱向模式下顯示單個頁面(默認模式是縱向)。旋轉到landcscape時,它應該並排顯示兩頁, 在我的ViewController的viewdidload方法中,我添加了以下內容如何在ios7中檢測旋轉的風景模式?

- (void)viewDidLoad 
{ 

     UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation]; 
     landscape=UIDeviceOrientationIsLandscape(deviceOrientation); 
    if(landscape) 
    { 
     //logic goes here 
    } 
    else 
    { 
    logic for portrait goes here 
    } 
} 

但它不爲我工作,只肖像邏輯越來越excecuted.Please幫助

回答

0

方向改變其處理方式稍有不同的方式。 當方向更改時,您的viewcontroller需要接收通知。

這裏的示例代碼:

@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) 
    { 
     isShowingLandscapeView = YES; 
     // logic for landscape orientation goes here 
    } 
    else if (UIDeviceOrientationIsPortrait(deviceOrientation) && 
      isShowingLandscapeView) 
    { 
     isShowingLandscapeView = NO; 
     // logic for portrait orientation goes here 
    } 
} 

獲得進一步的信息,請Apple documentation