将人像模式设置为横向 [英] set Portrait Mode to Landscape
问题描述
我尝试使用类别.... 添加新文件,然后选择Category,并创建子类UINavigationController类.
I tried using a Category.... Add new files and select Category and make subclass UINavigationController class.
这是.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
在应用程序委托中声明了
isLandscape以检查天气,第一个视图控制器或secondView控制器isLandscape是Bool.
isLandscape is declared in App delegate to check weather First view controller or secondView Controller isLandscape is Bool.
现在,我希望在Portarit模式下使用FirstViewController.m文件,所以使用此代码
Now FirstViewController.m file i want that in Portarit mode so used this code
- (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,我希望在横向"模式下使用它.
and SecondViewController i want that in Landscape mode used this one.
delegate.islandscape=NO; // called transfer to Category
- (NSInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
我将其引用为 Protrait中的第一个ViewController和Landscape中的SecondViewController模式和此 Landscape Apps Xcode 5/iOS 7 a>和其他但对我不起作用
I refer this 1st ViewController in Protrait and SecondViewController in Landscape Mode and this Landscape Apps Xcode 5 / iOS 7 and other but not working for me
推荐答案
在github上查看此项目 https://github.com/alloy/ForceOrientationTest
Have a look at this project on github https://github.com/alloy/ForceOrientationTest
这篇关于将人像模式设置为横向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!