Ios 自定义推送转换不是';t工作,而相同的自定义当前转换
我一直在关注这个问题,但我找不到答案 我的代码中有几乎相同的转换。当我把它作为一个显示视图,而不是一个推式视图时,它工作得非常好 当弹出时,它应该将推送视图的快照从CGRect动画化为全屏,反之亦然 以下是我的Ios 自定义推送转换不是';t工作,而相同的自定义当前转换,ios,swift,custom-transition,Ios,Swift,Custom Transition,我一直在关注这个问题,但我找不到答案 我的代码中有几乎相同的转换。当我把它作为一个显示视图,而不是一个推式视图时,它工作得非常好 当弹出时,它应该将推送视图的快照从CGRect动画化为全屏,反之亦然 以下是我的UIViewControllerAnimatedTransitioning类的代码: class ZoomingTransitionController: NSObject, UIViewControllerAnimatedTransitioning { let originFr
UIViewControllerAnimatedTransitioning
类的代码:
class ZoomingTransitionController: NSObject, UIViewControllerAnimatedTransitioning {
let originFrame: CGRect
let isDismissing: Bool
init(originFrame: CGRect, isDismissing: Bool) {
self.originFrame = originFrame
self.isDismissing = isDismissing
}
func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
return Constant.Animation.VeryShort
}
func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let containerView = transitionContext.containerView
guard let fromVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from),
let toVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to) else {
return
}
let finalFrame = transitionContext.finalFrame(for: toVC)
toVC.view.frame = finalFrame
let snapshot = self.isDismissing ? fromVC.view.snapshotView(afterScreenUpdates: true) : toVC.view.snapshotView(afterScreenUpdates: true)
snapshot?.frame = self.isDismissing ? finalFrame : self.originFrame
snapshot?.layer.cornerRadius = Constant.FakeButton.CornerRadius
snapshot?.layer.masksToBounds = true
containerView.addSubview(toVC.view)
containerView.addSubview(snapshot!)
if self.isDismissing {
fromVC.view.isHidden = true
} else {
toVC.view.isHidden = true
}
let duration = transitionDuration(using: transitionContext)
UIView.animate(withDuration: duration,
animations: {
snapshot?.frame = self.isDismissing ? self.originFrame : finalFrame
},
completion: { _ in
if self.isDismissing {
fromVC.view.isHidden = false
} else {
toVC.view.isHidden = false
}
snapshot?.removeFromSuperview()
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
})
}
}
然后,我尝试用两种方式显示一个新的视图控制器:通过显示它和通过推它
MyFromViewController
正在子类化UINavigationControllerDelegate
和UIViewControllerTransitioningDelegate
FromViewController
class演示到ViewController
(工作正常):
FromViewController
class将推送到ViewController
(不起作用):
当按下按钮时,将调用委托方法,缩放传递控制器将执行其代码(进入动画传递直到结束,没有明显问题)。但在屏幕上,快照视图在任何时候都不会显示。ToVC在转换持续时间之后出现,但同时没有任何其他内容
我已经不知道如何调试这个。。。你知道吗
谢谢 我通过用
toVC
的cGraffineTransform
替换snapshot元素(导致问题)找到了答案
代码几乎与相同。我通过将快照元素(导致问题的原因)替换为
toVC
的cAffineTransform
找到了答案
代码与几乎相同。您是否尝试在dispatchAsync和main queue的帮助下推送它?我尝试过,但没有帮助。我想问题出在我创建的快照上。您是否尝试过在dispatchAsync和main queue的帮助下推送它?我尝试过,没有帮助。我认为问题来自我创建的快照。
func buttonAction(_ sender: AnyObject) {
self.tappedButtonFrame = sender.frame
let toVC = self.storyboard!.instantiateViewController(withIdentifier: "ToViewController")
toVC.transitioningDelegate = self
self.present(toVC, animated: true, completion: nil)
}
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
let transitionController = ZoomingTransitionController(originFrame: self.tappedButtonFrame, isDismissing: false)
return transitionController
}
func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
let transitionController = ZoomingTransitionController(originFrame: self.tappedButtonFrame, isDismissing: true)
return transitionController
}
func buttonAction(_ sender: AnyObject) {
self.tappedButtonFrame = sender.frame
let toVC = self.storyboard!.instantiateViewController(withIdentifier: "ToViewController")
self.navigationController?.pushViewController(toVC, animated: true)
}
func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
switch operation {
case .push:
return ZoomingTransitionController(originFrame: self.tappedButtonFrame, isDismissing: false)
case .pop:
return ZoomingTransitionController(originFrame: self.tappedButtonFrame, isDismissing: true)
default:
return nil
}
}