在 iOS6 中处理旋转 [英] Handling Rotation in iOS6

查看:18
本文介绍了在 iOS6 中处理旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想在我的 UINavigationController 堆栈中的一个视图上支持不同的方向.我怎样才能做到这一点?

它也必须在 iOS5 中运行.

解决方案

我在 iOS6 如何处理 Orientation 方面遇到了很多麻烦,希望这就是您正在寻找的.

创建一个 UINavigationController 的类并命名为UINavigationController+autoRotate".

把它放在你的 UINavigationController+autoRotate.h 中:

#import @interface UINavigationController (autoRotate)-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation;-(BOOL)shouldAutorotate;- (NSUInteger)supportedInterfaceOrientations;@结尾

把这个放在 UINavigationController+autoRotate.m 中:

#import "UINavigationController+autoRotate.h"@implementation UINavigationController (autoRotate)-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{返回 [self.topViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];}- (BOOL)shouldAutorotate{返回 [self.visibleViewController shouldAutorotate];}- (NSUInteger)supportedInterfaceOrientations{if (![[self.viewControllers lastObject] isKindOfClass:NSClassFromString(@"ViewController")]){返回 UIInterfaceOrientationMaskAllButUpsideDown;}别的{返回 [self.topViewController supportedInterfaceOrientations];}}@结尾

对于不想旋转的视图,添加:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{return (interfaceOrientation == UIInterfaceOrientationPortrait);}- (NSUInteger)supportedInterfaceOrientations{返回 UIInterfaceOrientationMaskPortrait;}- (BOOL)shouldAutorotate{返回否;}

对于您确实想要旋转的视图:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{return (interfaceOrientation != UIDeviceOrientationPortraitUpsideDown);}- (NSUInteger)supportedInterfaceOrientations{返回 UIInterfaceOrientationMaskAllButUpsideDown;}- (BOOL)shouldAutorotate{返回是;}

在您应用的委托中,添加:

- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window{返回 UIInterfaceOrientationMaskAllButUpsideDown;}

I only want to support different Orientations on one View in my UINavigationController Stack. How can I do this?

It also has to work in iOS5.

解决方案

I've had a lot of trouble with how iOS6 handles Orientation, hopefully this is what you're looking for.

Create a category of UINavigationController and call it "UINavigationController+autoRotate".

Put this in your UINavigationController+autoRotate.h:

#import <UIKit/UIKit.h>

@interface UINavigationController (autoRotate)

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation;
-(BOOL)shouldAutorotate;
- (NSUInteger)supportedInterfaceOrientations;

@end

Put this in UINavigationController+autoRotate.m:

#import "UINavigationController+autoRotate.h"

@implementation UINavigationController (autoRotate)

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return [self.topViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
}

- (BOOL)shouldAutorotate
{
    return [self.visibleViewController shouldAutorotate];
}


- (NSUInteger)supportedInterfaceOrientations
{
    if (![[self.viewControllers lastObject] isKindOfClass:NSClassFromString(@"ViewController")])
    {
        return UIInterfaceOrientationMaskAllButUpsideDown;
    }
    else
    {
        return [self.topViewController supportedInterfaceOrientations];
    }
}

@end

For Views that you DO NOT want to rotate, add:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

- (BOOL)shouldAutorotate
{
    return NO;
}

And for Views you DO want to rotate:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIDeviceOrientationPortraitUpsideDown);
}

- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

- (BOOL)shouldAutorotate
{
    return YES;
}

In your App's delegate, add:

- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

这篇关于在 iOS6 中处理旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆