【发布时间】:2013-10-07 12:42:55
【问题描述】:
我尝试使用类别.... 添加新文件并选择 Category 并创建子类 UINavigationController 类。
这是 .h 的类别代码
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
@interface UINavigationController (orientation)
@end
code for .m file
#import "UINavigationController+orientation.h"
@implementation UINavigationController (orientation)
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
AppDelegate * delegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];
if (delegate.islandscape)
{
// for iPhone, you could also return UIInterfaceOrientationMaskAllButUpsideDown
return UIInterfaceOrientationMaskLandscape;
}
return UIInterfaceOrientationMaskPortrait;
}
@end
在 App 委托中声明 isLandscape 以检查天气 First view controller 或 secondView Controller isLandscape is Bool.
现在 FirstViewController.m 文件我希望在 Portarit 模式下使用此代码
- (IBAction)PlayClicked:(id)sender
{
AppDelegate * delegate=(AppDelegate *)[[UIApplication sharedApplication]delegate];
self.navigationController.navigationBarHidden=YES;
delegate.islandscape=YES;
ViewController * v=[[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
[self presentViewController:v animated:NO completion:nil];
//[self dismissViewControllerAnimated:YES completion:nil];
[self.navigationController pushViewController:v animated:YES];
}
- (NSInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
我希望 SecondViewController 在横向模式下使用这个。
delegate.islandscape=NO; // called transfer to Category
- (NSInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
我推荐这个 1st ViewController in Protrait and SecondViewController in Landscape Mode 和这个 Landscape Apps Xcode 5 / iOS 7 和其他但不适合我
【问题讨论】:
-
我知道这不是 xcode 问题...但这适用于 ios6 和 ios5 但不适用于 ios7....
标签: iphone objective-c