【问题标题】:Can't change the presentation and transition styles of modal views in Xcode (iPad)无法在 Xcode (iPad) 中更改模态视图的呈现和过渡样式
【发布时间】:2011-10-12 13:29:08
【问题描述】:

我目前在使用模态视图和弹出框时遇到了一些问题。可能是同样的问题,但我不确定。

我在使用模态视图时遇到的问题是我无法更改动画或过渡样式。例如,我写

self.modalPresentationStyle = UIModalPresentationPageSheet;
self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:IpModal animated:YES];

但模态视图仍以其原始过渡样式全屏显示。

此外,我遇到的弹出框问题也非常相似。即使我以“NO”作为参数调用dismissPopover:animated: 方法,过渡仍然是动画的。

提前致谢。

【问题讨论】:

    标签: ios xcode uipopovercontroller modalviewcontroller


    【解决方案1】:

    modalPresentationStylemodalTransitionStyle 适用于以模态方式呈现的视图控制器,而不是进行呈现的控制器。

    你的代码应该是

    IpModal.modalPresentationStyle = UIModalPresentationPageSheet;
    IpModal.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [self presentModalViewController:IpModal animated:YES];
    

    【讨论】:

    • +1 这也适用于在目标视图控制器上设置样式以通过将其设置为自身来解除样式。例如通过强制触摸预览视图控制器的情况,通过在目标端进行设置关闭的过渡似乎很灵活。
    • @haxpor 你能更详细地解释你的评论吗?
    • @LanceSamaria 如果我没记错的话。在 destination VC 设置解除过渡样式也很灵活;在我的情况下,将要显示的 VC。因此,对于原始 VC 中的管理代码来说,它会呈现另一个。
    【解决方案2】:

    我是在自定义 segue 中完成的。

    UIViewController* src = self.sourceViewController;
    UIViewController* dst = self.destinationViewController;
    
    src.modalPresentationStyle = UIModalTransitionStyleFlipHorizontal;
    dst.modalPresentationStyle = UIModalTransitionStyleFlipHorizontal;
    [src presentModalViewController:dst animated:YES];
    

    【讨论】:

      【解决方案3】:
      #import yourViewController.m //already present
      #import destinationVieController.m //to be added by programmer
      
      //custom function to call destination controller
      
      -(void)callDestinationViewController{
      
          destinationViewController *dest = [[destinationViewController alloc] initWithNibName:@"destinationViewController" bundle:nil];
      
          dest.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
          [self presentModalViewController:dest animated:YES];
      
        }
      
      //custom function can be called on event fire or action call
      

      希望这会有所帮助!

      【讨论】:

        【解决方案4】:

        也许您可以尝试使用这两种方法之一来呈现弹出框控制器,具体取决于您希望它出现的位置,而不是presentModalViewController:animated:

        – presentPopoverFromRect:inView:permittedArrowDirections:animated:
        – presentPopoverFromBarButtonItem:permittedArrowDirections:animated:
        

        【讨论】:

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