2013-01-02 111 views
2

我们的应用处于强制纵向模式。没有自动旋转,并且支持的界面方向被设置为肖像。纵向应用 - 横向模式视图 - 无自转

现在我们需要显示一个需要在横向上的“签名”视图。这应该在肖像视图上模态输入,并且需要有导航控制器和导航栏。它不应该能够旋转到肖像,并且当隐藏模式视图时,以前的视图仍然应该是纵向的。

我已经尝试使用:

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES]; 

但不旋转的导航栏......大概是因为supportedInterfaceOrientations需要返回0为它工作。

有什么办法可以做我需要的吗?使用笔尖(不是故事板)。

非常感谢

汤姆

+0

您将呈现/推送签名控制器或其刚被添加为子视图? –

+0

你只针对ios 6吗? –

+0

@Jennis作为模态视图呈现 –

回答

0

你需要让更多的(所有你想要的纵向和横向)为我描述的模式here.

原因: 如果您的应用程序只支持肖像,没有视图控制器能支持景观。 如果您的应用程序同时支持横向和纵向,则所有ViewController都可以定义其他限制。

在您所有的ViewController源中,您可以根据具体情况决定是否希望单个ViewController派生以允许纵向或横向。你也可以考虑为所有人像创建一个通用的超类。

1

其iPhone

第一支持的接口方向以yourview.m文件中设置的所有接口 然后

在yourview.h文件

 AppDelegate *appDel; 
BOOL isShowingLandscapeView; 
CGAffineTransform _originalTransform; 
CGRect _originalBounds; 
CGPoint _originalCenter; 
BOOL isLand,touch; 

-(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; 
} 


} 
+0

您好,这是有效的,它的作品没问题。唯一的问题是导航栏 - 我得到了更高的肖像导航栏,而不幸的是不是很短的景观导航栏。无论如何强迫它重画导航栏? –

+0

试试这个[self.navigationController setNavigationBarHidden:YES animated:YES]; ndz给我点 – 2013-01-03 04:49:38

2

刚请执行这些步骤。

  1. 使目标旋转。
  2. 制作的UINavigationController在您的应用程序委托类别(我想你的应用是导航的基础)像

-

@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 

希望这会有所帮助。

+0

这只适用于iOS 6 + –

+0

没有。它也适用于IOS 5。 shouldAutorotateToInterfaceOrientation方法是在IOS 6之前。 – fibnochi

+0

行得通。对不起,我错误的理解:) –

相关问题