我已经看到了其他类似的问题,但它并不适用于我的目的.我创建了一个LandscapeVIEwController,它是UIVIEwController的子类,我在这里编写了这些方法:
#pragma mark - OrIEntation Methods- (NSUInteger)supportedInterfaceOrIEntations{ return UIInterfaceOrIEntationMaskLandscape;}- (BOol)shouldautorotate{ return YES;}
当我按下详细视图控制器时,这是我的代码:
DetailVIEwController *detailVC = [[DetailVIEwController alloc] initWithNibname:@"DetailVIEwController" bundle:nil]; [self.navigationController pushVIEwController:detailVC animated:YES];
我正在考虑在上面的代码中将我的LandscapeVIEwController子类化到哪里以使其工作或如何正确地子类化并推送我的详细视图控制器.如果导航控制器无法将我的细节视图控制器从纵向推送到横向,我也可以以模态方式呈现我的详细视图控制器.我在哪里做错了?
解决方法 考虑到:视图A:仅限纵向 – 视图B:仅限横向
我无法在导航控制器中执行此 *** 作.相反,我所做的是从视图A打开模态视图以查看B并强制新的导航控制器进入此视图.
这在iOS5中对我有用.
您需要为导航控制器创建一个类别,如下所示:
UINavigationController Rotation_IOS6.h
#import <UIKit/UIKit.h> @interface UINavigationController (Rotation_IOS6)- (BOol)shouldautorotate;- (NSUInteger)supportedInterfaceOrIEntations;- (UIInterfaceOrIEntation)preferredInterfaceOrIEntationForPresentation;@end
UINavigationController Rotation_IOS6.h
#import "UINavigationController+Rotation_IOS6.h"@implementation UINavigationController (Rotation_IOS6)- (BOol)shouldautorotate{ return [self.topVIEwController shouldautorotate];}- (NSUInteger)supportedInterfaceOrIEntations{ return [self.topVIEwController supportedInterfaceOrIEntations];}- (UIInterfaceOrIEntation)preferredInterfaceOrIEntationForPresentation{ return [self.topVIEwController preferredInterfaceOrIEntationForPresentation];}@end
在AppDelegate.m中添加:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrIEntationsForWindow:(UIWindow *)window{ return UIInterfaceOrIEntationMaskAll;}
然后在视图A中:
- (BOol)shouldautorotate { return YES;}-(NSUInteger)supportedInterfaceOrIEntations{ return UIInterfaceOrIEntationMaskPortrait | UIInterfaceOrIEntationMaskPortraitUpsIDeDown;}- (UIInterfaceOrIEntation)preferredInterfaceOrIEntationForPresentation{ return UIInterfaceOrIEntationPortrait;}- (BOol)shouldautorotatetoInterfaceOrIEntation:(UIInterfaceOrIEntation)interfaceOrIEntation{ return (interfaceOrIEntation == UIInterfaceOrIEntationPortrait || interfaceOrIEntation == UIInterfaceOrIEntationPortraitUpsIDeDown);}
同样在VIEw A中打开VIEw B执行此 *** 作:
VIEwB *vc = [[VIEwB alloc] initWithNibname:@"VIEwB" bundle:nil];UINavigationController *navigationController = [[UINavigationController alloc] initWithRootVIEwController:vc];[self presentVIEwController:navigationController animated:YES completion:nil];
最后,在VIEw B中
- (BOol)shouldautorotate { return YES;}-(NSUInteger)supportedInterfaceOrIEntations{ return UIInterfaceOrIEntationMaskLandscapeRight | UIInterfaceOrIEntationMaskLandscapeleft;}- (UIInterfaceOrIEntation)preferredInterfaceOrIEntationForPresentation{ return UIInterfaceOrIEntationLandscapeRight;}- (BOol)shouldautorotatetoInterfaceOrIEntation:(UIInterfaceOrIEntation)interfaceOrIEntation{ return (interfaceOrIEntation == UIInterfaceOrIEntationLandscapeRight || interfaceOrIEntation == UIInterfaceOrIEntationLandscapeleft);}总结
以上是内存溢出为你收集整理的Objective-C中iOS 6上的强制横向方向全部内容,希望文章能够帮你解决Objective-C中iOS 6上的强制横向方向所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)