我正在使用UIPercentDrivenInteractiveTransition,当我将它与UIPanGestureRecognizer对象结合使用时,它可以正常工作。但是,当我关闭我的视图控制器(在didPan函数中)时,相关的内存不会被释放。你能解释一下为什么吗?我的代码如下:
class SecondViewController: UIViewController {
var panGestureRecognizer: UIPanGestureRecognizer!
var customInteractionAnimation = CustomInteractiveDismissAnimation()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = UIColor.clear
let myView = UIView(frame: CGRect(x: 30, y: 100, width: view.bounds.size.width - 60, height: 200))
myView.layer.cornerRadius = 10
myView.backgroundColor = UIColor.orange
panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(didPan))
view.addGestureRecognizer(panGestureRecognizer)
view.addSubview(myView)
}
required init?(coder aDecoder: NSCoder){
super.init(coder: aDecoder)
self.modalPresentationStyle = UIModalPresentationStyle.custom
transitioningDelegate = self
}
func didPan(){
switch panGestureRecognizer.state{
case .began:
customInteractionAnimation.interactive = true
print("Did PAN")
//performSegue(withIdentifier: "mySegue2", sender: self)
dismiss(animated: true, completion: nil)
default:
customInteractionAnimation.handelPan(recognizer: panGestureRecognizer!)
}
}
@IBAction func goToFirstViewController(_ segue: UIStoryboardSegue){
}
deinit {
print("Second view contoller was deallocated!")
}
}
extension SecondViewController: UIViewControllerTransitioningDelegate{
func presentationController(forPresented presented: UIViewController, presenting: UIViewController?, source: UIViewController) -> UIPresentationController? {
return CustomUIPresentationController(presentedViewController: presented, presenting: presenting)
}
func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return CustomAnimationController()
}
func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return CustomDismissAnimation()
}
func interactionControllerForDismissal(using animator: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? {
if !customInteractionAnimation.interactive{
return nil
} else {
print("Returned Interaction animation object")
return customInteractionAnimation
}
}
}
P.S。对不起凌乱的代码感到抱歉。
编辑:这是我的演示控制器
class CustomUIPresentationController: UIPresentationController {
lazy var gradientView = GradientDimmingView(frame: CGRect.zero)
override func presentationTransitionWillBegin() {
gradientView.frame = containerView!.bounds
containerView?.insertSubview(gradientView, at: 0)
gradientView.alpha = 0
if let coordinator = presentedViewController.transitionCoordinator{
coordinator.animate(alongsideTransition: {_ in
self.gradientView.alpha = 1
}, completion: nil)
}
}
override var shouldRemovePresentersView: Bool {
return false
}
}