2

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

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

我试过使用:

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

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

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

非常感谢

汤姆

4

3 回答 3

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

希望这会有所帮助。

于 2013-01-02T13:15:00.300 回答
1

它的 iPhone

首先设置支持的界面方向 All Interface then

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


 }
于 2013-01-02T12:58:32.977 回答
0

您需要允许更多(所有您想要的纵向和横向)模式,正如我在此处描述的那样。

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

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

于 2013-01-02T12:57:49.237 回答