App中的应用程序 - 横向模态视图 - 无自动旋转

时间:2013-01-02 11:19:49

标签: iphone ios ipad rotation

我们的应用程序处于强制纵向模式。没有自动旋转,支持的界面方向仅设置为纵向。

现在我们需要展示一个需要在景观中的“签名”视图。这应该在纵向视图上以模态方式输入,并且需要具有导航控制器和导航栏。它不应该旋转为纵向,并且当隐藏模态视图时,前一个视图仍然应该是纵向。

我尝试过使用:

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

但这不会旋转导航栏...大概是因为supportedInterfaceOrientations需要返回0才能工作。

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

非常感谢

汤姆

3 个答案:

答案 0 :(得分:2)

只需执行以下步骤。

  1. 在目标中进行旋转。
  2. 在您的app委托中创建一个UINavigationController类别(我认为您的应用是导航基础),如
  3. -

    @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
    

    希望这会有所帮助。

答案 1 :(得分:1)

用于iPhone

首先支持的接口方向设置为All Interface 然后

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


 }

答案 2 :(得分:0)

您需要允许更多(所有您想要的纵向和横向)模式,如我所描述的here.

原因: 如果您的应用程序仅支持纵向,则ViewController不支持横向。 如果您的应用程序同时支持横向和纵向,则所有ViewControllers都可以定义进一步的限制。

在所有ViewControllers的源代码中,如果您希望单个ViewController派生允许纵向或横向,您可以根据具体情况决定。您还可以考虑为所有肖像等创建一个共同的超类。

相关问题