处理iOS6中的旋转 [英] Handling Rotation in iOS6
问题描述
我只想在我的UINavigationController堆栈中的一个View上支持不同的Orientations。我怎样才能做到这一点?
它也必须在iOS5中运行。
我'我对iOS6如何处理Orientation有很多麻烦,希望这是你正在寻找的。 p>
创建一个UINavigationController类并称之为UINavigationController + autoRotate 。
把它放在你的UINavigationController + autoRotate.h中:
#import< UIKit / UIKit.h>
@interface UINavigationController(autoRotate)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation;
- (BOOL)shouldAutorotate;
- (NSUInteger)supportedInterfaceOrientations;
@end
将此放入UINavigationController + autoRotate.m:
#importUINavigationController + 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) ])
{
返回UIInterfaceOrientationMaskAllButUpsideDown;
}
else
{
return [self.topViewController supportedInterfaceOrientations];
}
}
@end
您不想旋转的视图,添加:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return(interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (NSUInteger)supportedInterfaceOrientations
{
返回UIInterfaceOrientationMaskPortrait;
}
- (BOOL)shouldAutorotate
{
return NO;
}
对于你想要旋转的视图:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return(interfaceOrientation!= UIDeviceOrientationPortraitUpsideDown);
}
- (NSUInteger)supportedInterfaceOrientations
{
返回UIInterfaceOrientationMaskAllButUpsideDown;
}
- (BOOL)shouldAutorotate
{
返回YES;
}
在你的App代表中,添加:
- (NSUInteger)应用程序:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return 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屋!