Iphone 纵向应用程序-横向模式视图-无自动旋转
我们的应用程序处于强制肖像模式。没有自动旋转,支持的界面方向设置为仅纵向 现在,我们需要显示一个“签名”视图,它需要处于横向。这应该通过纵向视图进行模式输入,并且需要有导航控制器和导航栏。它应该不能旋转到纵向,并且当模式视图被隐藏时,前一个视图仍应处于纵向 我试过使用:Iphone 纵向应用程序-横向模式视图-无自动旋转,iphone,ios,ipad,rotation,Iphone,Ios,Ipad,Rotation,我们的应用程序处于强制肖像模式。没有自动旋转,支持的界面方向设置为仅纵向 现在,我们需要显示一个“签名”视图,它需要处于横向。这应该通过纵向视图进行模式输入,并且需要有导航控制器和导航栏。它应该不能旋转到纵向,并且当模式视图被隐藏时,前一个视图仍应处于纵向 我试过使用: [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES]; 但这不
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES];
但这不会旋转导航栏。。。大概是因为supportedInterfaceOrientations
需要返回0才能工作
有什么办法可以满足我的需要吗?使用NIB(而不是故事板)
非常感谢
Tom如我所述,您需要允许更多(所有您想要的纵向和横向)模式
原因:
如果应用程序仅支持纵向,则没有ViewController可以支持横向。
如果应用程序同时支持横向和纵向,则所有ViewController都可以定义进一步的限制
在所有ViewController的源代码中,您可以根据具体情况决定是否希望单个ViewController派生为允许纵向或横向。您还可以考虑为所有肖像画等创建一个通用的超级类。它适用于iPhone
首先,支持的接口方向设置为所有接口
然后
在yourview.h文件中
AppDelegate *appDel;
BOOL isShowingLandscapeView;
CGAffineTransform _originalTransform;
CGRect _originalBounds;
CGPoint _originalCenter;
BOOL isLand,touch;
在yourview.m文件中
-(void)viewWillAppear:(BOOL)animated
{
isLand = NO;
appDel = (AppDelegate*)[[UIApplication sharedApplication] delegate];
[[UIApplication sharedApplication] setStatusBarHidden:TRUE withAnimation:UIStatusBarAnimationNone];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
_originalTransform = [[appDelegate navigationController].view transform];
_originalBounds = [[appDelegate navigationController].view bounds];
_originalCenter = [[appDelegate navigationController].view center];
[appDelegate navigationController].view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
//[appDelegate navigationController].view.bounds = CGRectMake(0.0,20.0, 480.0, 320.0);
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(M_PI/2);
landscapeTransform = CGAffineTransformTranslate (landscapeTransform, +60.0, +80.0);
[[appDelegate navigationController].view setTransform:landscapeTransform];
[appDelegate navigationController].view.bounds = CGRectMake(-20.0,00.0, 480.0, 320.0);
[appDelegate navigationController].view.center = CGPointMake (240.0, 160.0);
}
if(result.height == 568)
{
CGAffineTransform landscapeTransform = CGAffineTransformMakeRotation(M_PI/2);
landscapeTransform = CGAffineTransformTranslate (landscapeTransform, +124.0, +124.0);
[[appDelegate navigationController].view setTransform:landscapeTransform];
[appDelegate navigationController].view.bounds = CGRectMake(0.0,0.0, 568, 320.0);
[appDelegate navigationController].view.center = CGPointMake (284, 160.0);
}
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationLandscapeLeft;
}
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
CGSize result = [[UIScreen mainScreen] bounds].size;
if(result.height == 480)
{
[appDelegate navigationController].view.bounds = CGRectMake(0.0,0.0, 480.0, 320.0);
}
if(result.height == 568)
{
[appDelegate navigationController].view.bounds = CGRectMake(0.0,0.0, 568, 320.0);
}
// [appDelegate navigationController].view.bounds = CGRectMake(0.0,0.0, 480.0, 320.0);
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if(interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight)
{
return YES;
}
else
{
return NO;
}
}
- (void) viewWillDisappear:(BOOL)animated {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[[appDelegate navigationController].view setTransform:_originalTransform];
[[appDelegate navigationController].view setBounds:_originalBounds];
[[appDelegate navigationController].view setCenter:_originalCenter];
if (isLand == NO) {
isLand = YES;
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeRight;
} else {
isLand = NO;
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait;
}
}
只需执行这些步骤
希望这会有所帮助。您将演示/推送签名控制器,或者只是将其添加为子视图?您是否仅针对ios 6?@Jennis演示为模式视图否。它也适用于iOS5。应该在IOS 6之前使用AutoRotateTointerFaceOrientation方法。这对我不起作用,你能给我一些关于如何强制旋转的更多信息吗?非常感谢。我们可以聊聊吗?那么我可以更好地帮助你。嗨,这很有效,老实说也很有效。唯一的问题是导航栏-我得到的是更高的纵向导航栏,而不是短的横向导航栏不幸。是否仍有强制它重新绘制导航栏的方法?请尝试此方法[self.navigationController setNavigationBarHidden:YES动画:YES];请给我一分
@interface UINavigationController (Autorotation)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation - (BOOL) shouldAutorotate;
- (NSUInteger) supportedInterfaceOrientations;
@end
@implementation UINavigationController (Autorotation)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
if ([self.visibleViewController isKindOfClass:["your view controller name" class]]) {
return YES;
}
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
-(BOOL) shouldAutorotate{
return YES;
}
-(NSUInteger) supportedInterfaceOrientations{
if ([self.visibleViewController isKindOfClass:["your view controller name" class]]) {
return UIInterfaceOrientationMaskAll;
}
return UIInterfaceOrientationMaskPortrait;
}
@end