不知楼主有没有测试过,在Modal转场实践中,这段代码会有一个小小的内存问题。多次present、dimiss切换,内存会一直以0.1M的增量上涨,不会回落,用Xcode的Leaks工具检测,并没有发现内存泄漏,我尝试着打印了containerView的subViews,发现并没有什么异常。我尝试着在这个OverlayAnimationController类中添加了一个 weak var maskView来替代原有的dimmingView,并且在dismiss中将fromView从containerView中移除,发现内存并没有回落。有些困惑,特来请教,谢谢了!
class OverlayAnimationController: NSobject, UIViewControllerAnimatedTransitioning{ ... func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
... //不像容器 VC 转场里需要额外的变量来标记操作类型,UIViewController 自身就有方法跟踪 Modal 状态。 //处理 Presentation 转场: if toVC.isBeingPresented(){ //1 containerView.addSubview(toView) //在 presentedView 后面添加暗背景视图 dimmingView,注意两者在 containerView 中的位置。 let dimmingView = UIView() containerView.insertSubview(dimmingView, belowSubview: toView)
}
不知楼主有没有测试过,在Modal转场实践中,这段代码会有一个小小的内存问题。多次present、dimiss切换,内存会一直以0.1M的增量上涨,不会回落,用Xcode的Leaks工具检测,并没有发现内存泄漏,我尝试着打印了containerView的subViews,发现并没有什么异常。我尝试着在这个OverlayAnimationController类中添加了一个 weak var maskView来替代原有的dimmingView,并且在dismiss中将fromView从containerView中移除,发现内存并没有回落。有些困惑,特来请教,谢谢了!