我正在使用自定义转换在- presentViewController:animated:completion:
调用时将视图控制器2/3滑出屏幕,并在dismissViewControllerAnimated:completion:
调用时再次将其向后滑动.
我还使用UIPercentDrivenInteractiveTransition附加到a UIScreenEdgePanGestureRecognizer
来滑动视图控制器.
一切正常,除非在致电dismissViewControllerAnimated:completion:
之前,之前:
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext
Run Code Online (Sandbox Code Playgroud)
被称为视图控制器的框架滑出屏幕被设置为:
(0 0; 320 568)
Run Code Online (Sandbox Code Playgroud)
导致它在动画运行之前暂时"闪烁",并从屏幕上的2/3滑回到全屏.
通过在View Controller上继承UIView,我可以在-setFrame
其中设置一个断点,显示方法:
[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:animation:]
Run Code Online (Sandbox Code Playgroud)
呼吁-setFrame
用(0 0; 320 568)
.
它为什么这样做?如何防止它在动画开始前设置框架?
我有两个viewControllers:
ViewController1
一组复杂的子视图控制器,中间有一个imageView
ViewController2
包含imageView的scrollView
我想要实现的是两个viewControllers之间的转换,它通过从viewController 1捏合imageView来触发,使其放大并切换到viewController 2.当转换结束时,imageView应该放大到目前为止因为它在捏合手势触发过渡期间被缩放.
同时我想支持在执行缩放转换时平移图像,这样就像缩放一样,处于结束状态的图像将被转换到它被平移到的位置.
到目前为止,我已经尝试过Hero过渡pod和我自己编写的自定义viewController过渡.英雄转换的问题是图像没有正确地捕捉到第二个viewController中的结束状态.我对自定义viewController转换的问题是我无法同时进行缩放和平移.
有没有人知道如何在Swift中实现它?非常感谢帮助.
我正在使用UIPresentationController呈现模态视图控制器.我使用以下方法设置presentView的框架小于containsView的边界:
override func frameOfPresentedViewInContainerView() -> CGRect {
let myDX = (self.containerView!.bounds.width - 600)/2
let myDY = (self.containerView!.bounds.height - 600)/2
return self.containerView!.bounds.insetBy(dx: myDX, dy: myDY)
}
Run Code Online (Sandbox Code Playgroud)
到目前为止,一切都很好.
现在,我在当前显示的模式视图控制器顶部呈现另一个视图控制器(默认不是自定义),它占用整个屏幕.所以,我在默认模态视图控制器下面有一个自定义模态视图控制器,覆盖整个屏幕.
问题是当我关闭覆盖整个屏幕的顶视图控制器时,我的自定义视图控制器也显示覆盖整个屏幕.我希望我的自定义视图控制器的大小保持不变(小于containerView).有什么方法可以实现这一点.
任何帮助,将不胜感激
uikit uikit-transitions ios8 uipresentationcontroller uitraitcollection
我有一个演示应用程序,我试图在其中模拟邮件应用程序的“新消息”交互式转换 - 您可以向下拖动以关闭,但如果您拖动的距离不够远,则视图会重新弹出并取消转换。我能够在我的演示应用程序中复制过渡和交互性,但我注意到当取消关闭过渡时,呈现的视图控制器动画回到原位,然后消失。这是它的样子:
我最好的猜测是由于某种原因正在删除转换上下文的容器视图,因为我向它添加了呈现的视图控制器的视图。这是UIViewControllerAnimatedTransitioning
对象内的演示和关闭代码:
显示过渡
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
guard let fromVC = transitionContext.viewController(forKey: .from),
let toVC = transitionContext.viewController(forKey: .to)
else {
return
}
let containerView = transitionContext.containerView
let finalFrame = transitionContext.finalFrame(for: toVC)
let duration = transitionDuration(using: transitionContext)
let topSafeAreaSpace = fromVC.view.safeAreaInsets.top // using fromVC safe area since it's on screen and has correct insets
let topGap: CGFloat = topSafeAreaSpace + 20
containerView.addSubview(toVC.view)
toVC.view.frame = CGRect(x: 0,
y: containerView.frame.height,
width: toVC.view.frame.width,
height: toVC.view.frame.height - 30)
UIView.animate(withDuration: duration, …
Run Code Online (Sandbox Code Playgroud)