2013-01-02 110 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

行得通。對不起,我錯誤的理解:) –

相關問題