【问题标题】:Error to present view controller centered in iPad iOS 6以 iPad iOS 6 为中心呈现视图控制器时出错
【发布时间】:2012-09-15 20:09:38
【问题描述】:

在 iOS 5 中它可以正常运行:

PinRequiredViewController *pinView = [[PinRequiredViewController alloc]initWithNibName:@"PinRequiredView" bundle:nil];

            UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:pinView];

            // show the navigation controller modally
            navController.modalPresentationStyle = UIModalPresentationFormSheet;
            navController.modalInPopover = NO;
            navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;

            [self presentViewController:navController animated:YES completion:nil];

            navController.view.superview.frame = CGRectMake(0, 0, 250, 250);

            navController.view.superview.center = self.view.window.center;

但在 iOS6 中无法正常工作,视图不会在屏幕中保持居中,无论是纵向还是横向。 有什么解决办法吗?

谢谢!! :)

【问题讨论】:

  • 我有同样的问题,无法解决。在 iOS 6 之前可以正常工作。
  • @Javi_576 这到底是什么问题?说“不起作用”的问题并不是对问题的全面描述。你是说它根本不存在?
  • 不,视图在 iOS5 中使用此代码居中,但在 iOS6 中没有。

标签: objective-c ios ios5 uinavigationcontroller ios6


【解决方案1】:

我认为如果您删除 UIModalTransitionStyleFlipHorizontal 过渡样式并改用其他过渡样式之一,它会起作用。

似乎这是UIModalTransitionStyleFlipHorizontal 的错误。

【讨论】:

  • 谢谢各位!这是一个错误,因为我使用了另一个 UIModalTransitionStyle 并且运行正常! :)
【解决方案2】:

在您的 presentViewController 中使用完成:

[self presentViewController:navController animated:YES completion:^{
        navController.view.superview.bounds = CGRectMake(0, 0, 250, 250);}];

这将使它与UIModalTransitionStyleFlipHorizontal 一起工作。

【讨论】:

  • 这是朝着正确方向迈出的一步,但在动画完成之前,模态动画的大小不正确。最终结果令人震惊。
  • 在 iOS6 上,在 presentViewController:animated:completion: 之后的 navCon.view.superview.bounds = CGRectMake(0, 0, kPopupsWidth, kPopupsHeight) 过去可以工作,但在 iOS7(Beta 5)上不再有效。视图已调整大小,但未居中...完成后有效,但动画丑陋!
【解决方案3】:

问题是您可以将超级视图的框架设置为您想要的任何内容,但原点不会更改。这就是它不居中的原因。

看起来 Apple 在 iOS6 中故意限制了这一点

【讨论】:

    【解决方案4】:

    我成功了:

    aboutViewController.modalPresentationStyle = UIModalPresentationFormSheet;
    aboutViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    
    CGRect aboutSheetFrame = aboutViewController.view.frame;
    [self presentViewController:aboutViewController animated:YES completion:^{
            aboutViewController.view.superview.bounds = aboutSheetFrame;
            }];
    aboutViewController.view.superview.bounds = aboutSheetFrame;
    

    在 ios 6.1 beta 2 上使用 UIModalTransitionStyleFlipHorizontal 转换仍然存在问题。 aboutSheetFrame 是为了避免尺寸硬编码。

    【讨论】:

      【解决方案5】:

      根据我对 UIModalTransitionStyleFlipHorizo​​ntal 的理解,唯一的出路是首先呈现不带动画的视图,设置中心点,然后在下一行中将其关闭,然后再次以动画显示它:是的。如下图.....

      [self presentViewController:navController animated:NO completion:nil];
      
      CGPoint centerPoint = CGPointMake([[UIScreen mainScreen] bounds].size.width/2, [[UIScreen mainScreen] bounds].size.height/2);
      navController.view.superview.center = centerPoint;
      [navController dismissModalViewControllerAnimated:NO];
      
      navController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
      [self presentViewController:navController animated:YES completion:nil]; 
      

      【讨论】:

        【解决方案6】:

        只需在 viewDidAppear 而不是 viewDidLoad 中执行。你已经排序了!

        【讨论】:

          【解决方案7】:

          对于 iOS 7 试试这个:

          [self.navigationController presentViewController:navigationController animated:YES completion:^{
              //Make the modal bigger than normal
              navigationController.view.superview.bounds = CGRectMake(0, 0, 700, 650);
          }];
          

          动画看起来很难看,所以我建议添加一个动画来改进它:

          [self.navigationController presentViewController:navigationController animated:YES completion:^{
              [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseIn animations:^{
                  //Make the modal bigger than normal
                  navigationController.view.superview.bounds = CGRectMake(0, 0, 700, 650);
              } completion:^(BOOL finished) {
              }];
          }];
          

          还请记住,您需要在 viewDidAppear 中设置 navigationControllers 视图的框架,以使内容的大小正确。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2011-01-20
            • 1970-01-01
            • 1970-01-01
            • 2016-02-03
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2019-03-10
            相关资源
            最近更新 更多