如何在景观中启动应用程序? (沮丧)

时间:2012-12-17 09:03:32

标签: iphone objective-c cocoa-touch landscape uiinterfaceorientation

这个问题应该是一个简单的... 我已经搜索了很多关于它的东西,我已经尝试了我项目的所有设置。 问题是我正在研究一个不属于我的项目。从应用程序委托启动的应用程序,然后我添加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:terminate调用抛出异常

如果我以纵向模式编写应用程序,则会启动。我还尝试在info.plist中添加行,并将键设置为横向的初始界面方向值(右主页按钮)。 还将支持的界面方向也放在了lanscape上。 没有任何改变,我只想知道如何在横向模式下获得上述通知

任何人,谢谢!

1 个答案:

答案 0 :(得分:0)

  

在您的app delegate .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