2

這個問題應該是一個簡單的... 我已經搜索了很多關於它,我已經嘗試了我的項目上的所有設置。 事情是我正在一個不是我的項目上工作。從應用程序代理啓動的應用程序,然後我添加一個UIViewController(沒有XIB文件)所有代碼完成。 ViewController實際上是在風景上,但事情是應用程序正在肖像上運行(當我拉動通知視圖時,它將像肖像模式下變成一樣)。如何在景觀中啓動應用程序? (沮喪)

這是在AppDelegate.m文件中實現:

- (NSUInteger)supportedInterfaceOrientations 
{ 
return UIInterfaceOrientationLandscapeRight; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
// Return YES for supported orientations 
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
} 



- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
{                          

return UIInterfaceOrientationMaskLandscapeRight|UIInterfaceOrientationMaskLandscapeLeft|UIInterfaceOrientationMaskPortrait; 

//if i am writing only the landscape right orientation the app crashes! 



} 

*終止應用程序由於未捕獲的異常「UIApplicationInvalidInterfaceOrientation」,理由是:「支持的方向與應用程序中沒有共同的方向,並shouldAutorotate正在恢復YES」 *第一擲調用堆棧: (0x3bfef2a3 0x35ede97f 0x3bfef1c5 0x3518988f 0x3532e579 0x3520dd3d 0x3520cfc7 0x3532f257 0xa5bc1 0x35188319 0x351a4f0f 0x351a4e97 0x3512aa33 0x3bfc46cd 0x3bfc29c1 0x3bfc2d17 0x3bf35ebd 0x3bf35d49 0x3a3032eb 0x351752f9 0x9803b 0x97fe0) libC++ abi.dylib:終止調用拋出異常

如果我用縱向模式編寫應用程序啓動。我還嘗試在info.plist中添加行,並將關鍵字設置爲風景的初始界面方向值(右側主頁按鈕)。 也支持接口定位到lanscape。 非此變化的任何東西,我只是想知道我如何得到這種行爲,從風景模式獲得上述通知

任何人,謝謝!

回答

0

試試這個辦法在你的應用程序代理.m文件...

#define IOS_OLDER_THAN_6 ([ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] < 6.0) 
    #define IOS_NEWER_OR_EQUAL_TO_6 ([ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] >= 6.0) 



     - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
     { 


      self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 

      [NSThread sleepForTimeInterval:0.1]; // simulate waiting for server response 

      // Override point for customization after application launch. 

      self.viewController = [[[ViewController alloc] init] autorelease]; 

      // Initialise the navigation controller with the first view controller as its root view controller 

      UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController]; 

      // This is where we hide the navigation bar! :) 

      [navigationController setNavigationBarHidden:NO]; 

      // Navigation controller has copy of view controller, so release our copy 


       [self.viewController release]; 

      // Add the navigation controller as a subview of our window 

      if ([[UIDevice currentDevice].systemVersion floatValue] < 6.0) 
      { 
       // how the view was configured before IOS6 
       [self.window addSubview: navigationController.view]; 
       // [self.window makeKeyAndVisible]; 
      } 
      else 
      { 
       // this is the code that will start the interface to rotate once again 
     //  [self.window setRootViewController: self.navigationController]; 
       [self.window setRootViewController:navigationController]; 
      } 

     // [self.window setRootViewController:navigationController]; 
      [_window makeKeyAndVisible]; 
      return YES; 
     } 


    #ifdef IOS_OLDER_THAN_6 
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ 
     // [image_signature setImage:[self resizeImage:image_signature.image]]; 
     return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft | toInterfaceOrientation == UIInterfaceOrientationLandscapeRight); 
    } 
    #endif 

    #ifdef IOS_NEWER_OR_EQUAL_TO_6 
    -(BOOL)shouldAutorotate { 
     return YES; 
    } 
    - (NSUInteger)supportedInterfaceOrientations { 
     // [image_signature setImage:[self resizeImage:image_signature.image]]; 
     //return UIInterfaceOrientationMaskLandscapeLeft; 
     return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight; 
    } 
    #endif 

    - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
    { 
     return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight; 
    } 

**`

而且還寫下你的所有鑑於此代碼控制器.m文件

`**

#define IOS_OLDER_THAN_6 ([ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] < 6.0) 
#define IOS_NEWER_OR_EQUAL_TO_6 ([ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] >= 6.0) 


#ifdef IOS_OLDER_THAN_6 
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{ 
    // [image_signature setImage:[self resizeImage:image_signature.image]]; 
    //return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft | toInterfaceOrientation == UIInterfaceOrientationLandscapeRight); 
    if(toInterfaceOrientation ==UIInterfaceOrientationLandscapeLeft){ 
     NSLog(@"Changed Orientation To Landscape left"); 

     return (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft); 

    }else{ 
     NSLog(@"Changed Orientation To Landscape right"); 
     return (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight); 
    } 
} 
#endif 

#ifdef IOS_NEWER_OR_EQUAL_TO_6 
-(BOOL)shouldAutorotate { 
    return YES; 
} 
- (NSUInteger)supportedInterfaceOrientations { 
    // [image_signature setImage:[self resizeImage:image_signature.image]]; 
    //return UIInterfaceOrientationMaskLandscapeLeft; 
    return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight; 
} 
#endif 
+0

首先感謝您的快速反應,但我沒有使用UINavigation控制器 –

+0

OK,那麼你必須使用這個代碼,而無需UINavigation控制器,這是工作.. –

+0

這是行不通的,應用程序仍然崩潰 –