相关疑难解决方法(0)

UIViewController - 自定义解除转换的问题

摘要

我有一个内容UIViewController,它使用自定义转换呈现设置UIViewController.演示文稿是presentViewController:animated:completion:.

当我稍后解除设置时dismissViewControllerAnimated:completion:,呈现控制器突然跳回设置控制器演示之前的初始位置.

我在设备上有一个解决方法,但不是模拟器.但是,我想知道我做错了什么而不是黑客入侵让它消失的小屋.我还打算让这个动画互动,我怀疑这个问题会在我这样做时放大.

定制过渡 - 打开引擎盖

期望的效果是呈现控制器在屏幕上向下滑动,并且看到呈现的控制器位于其后面,从其抬起以填充屏幕.在呈现控制器的使用寿命期间,呈现控制器的顶部保持在屏幕上.它停留在屏幕的底部,但位于显示的控制器上方.

您可以想象在汽车(前部控制器)上抬起发动机罩以查看后面的发动机(显示的设置),但发动机罩在底部保持可见,以获得一些背景信息.

我计划对其进行改进,以便呈现控制器真正看起来以3d方式提升视角,但我还没有那么远.

当设置被取消时,原始呈现控制器(发动机罩)应向上滑回屏幕,并且呈现的控制器(设置)稍微下沉(关闭发动机罩).

这是切换屏幕上和屏幕外设置的方法(它只是由UIButton调用).你会注意到呈现视图控制器将自己设置为<UIViewControllerTransitioningDelegate>.

-(void) toggleSettingsViewController
{
  const BOOL settingsAreShowing = [self presentedViewController] != nil;
  if(!settingsAreShowing)
  {
    UIViewController *const settingsController = [[self storyboard] instantiateViewControllerWithIdentifier: @"STSettingsViewController"];
    [settingsController setTransitioningDelegate: self];
    [settingsController setModalPresentationStyle: UIModalPresentationCustom];
    [self presentViewController: settingsController animated: YES completion: nil];
  }
  else
  {
    [self dismissViewControllerAnimated: YES completion: nil];
  }
}
Run Code Online (Sandbox Code Playgroud)

要实现<UIViewControllerAnimatedTransitioning>呈现视图控制器,也只需返回自身<UIViewControllerAnimatedTransitioning>

-(id<UIViewControllerAnimatedTransitioning>) animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting …
Run Code Online (Sandbox Code Playgroud)

uiviewcontroller uikit uiviewanimationtransition ios

26
推荐指数
1
解决办法
3万
查看次数