动画后导航控制器设置为nil

时间:2018-10-05 19:50:16

标签: ios swift animation uicollectionview uinavigationcontroller

早上好,感谢您的阅读! 在我的项目中,我使用的是UICollectionViewController,并且实现了一个动画,可以在触摸时扩展它的单元格。如果您不希望这样做,请查看App Store的“今日”部分。我的CVC嵌入在导航控制器中,因为我在视图中使用了导航项。展开时,我将其关闭了,这似乎导致我的视​​图剪切到了安全区域,因为iPhone X上的单元格没有完全展开。这是第一个问题,但主要的问题是,当我将导航控制器设置为零时导航项不会崩溃(崩溃时)。

这里是选择单元格时调用的函数:

func animateCell(_ cell: BookCell, style: CellAnimationStyle) {

    //...

    let dampingRatio: CGFloat = 0.8
    let initialVelocity: CGVector = CGVector.zero
    let springParameters: UISpringTimingParameters = UISpringTimingParameters(dampingRatio: dampingRatio, initialVelocity: initialVelocity)
    let animator = UIViewPropertyAnimator(duration: 0.8, timingParameters: springParameters)

    self.view.isUserInteractionEnabled = false
    self.CollectionView.isScrollEnabled = (style == .Collapse)

    let NVC = self.navigationController!

    if style == .Expand {
        self.expandedCell = cell
        NVC.setNavigationBarHidden(true, animated: true)
    } else {
        DispatchQueue.main.async {
            self.expandedCell = nil
            NVC.setNavigationBarHidden(false, animated: true)
        }
    }

    animator.addAnimations {

        if style == .Expand {
            self.statusBarHidden = true
            self.CollectionView.bringSubviewToFront(cell)
            cell.expand(collectionView: self.CollectionView)
        } else {
            self.statusBarHidden = false
            cell.collapse(collectionView: self.CollectionView)
        }
    }

    animator.addCompletion() { _ in
        DispatchQueue.main.async {
            self.view.isUserInteractionEnabled = true
            self.CollectionView.isScrollEnabled = (style == .Collapse)
        }
        if style == .Expand {
            cell.isExpanded = true
        } else {
            cell.isExpanded = false

        }
    }
    animator.startAnimation()

    self.setNeedsStatusBarAppearanceUpdate()
    cell.layoutIfNeeded()
}

然后,当单元格展开时,它会获得一个链接到此IBAction的关闭按钮:

@IBAction func didTouchCollapse(_ sender: UIButton) {

    guard let nc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "BookNC") as? UINavigationController else { return }
    guard let delegate = nc.children.first as? ChaptersCollectionViewDelegate else { return }

    delegate.collapseCell(self, style: .Collapse)

}

委托方法仅使用单元格和样式.Collapse作为参数调用animateCell()。 非常感谢您的帮助!

0 个答案:

没有答案
相关问题