【问题标题】:Custom unwind segue animation display issue自定义展开 segue 动画显示问题
【发布时间】:2017-02-15 20:41:21
【问题描述】:

我正在制作我的第一个自定义 segue 动画。我想要的是有一个列表视图,当我在一行上选择时,它不是从侧面滑入,而是从所选行中展开到位。比如:

所以用户选择了绿色行,这会导致新控制器以绿色行大小开始并展开以填满屏幕。到目前为止,这部分运行良好。

我遇到的问题是 unwind segue 试图做相反的事情,将全屏缩小到原始行然后关闭。发生的情况是它缩小得很好,但暴露的区域仍然是黑色,然后在动画完成时突然闪烁到位。想要的是这样的:

但是发生的事情更像是这样的:

我用于展开的perform 的代码如下:

class FromScheduleFocusSegue: UIStoryboardSegue {
    override func perform() {
        let fromView = self.source.view!
        let toView = self.destination.view!
        let window = UIApplication.shared.keyWindow!
        let schedulesList = self.destination as! SchedulesListController
        let cell = schedulesList.tableView.cellForRow(at: schedulesList.tableView.indexPathForSelectedRow!)!
        var stripe = cell.bounds
        stripe.size.height = 60
        let targetFrame = cell.convert(stripe, to: window).insetBy(dx: 0, dy: 0)
        schedulesList.tableView.selectRow(at: nil, animated: false, scrollPosition: .none)
        UIView.animateWithDuration(4000.milliseconds, delay: 0.seconds, options: .curveEaseInOut, animations: {
            fromView.frame = targetFrame
        }) { (finished) in
            self.source.dismiss(animated: false, completion: nil)
        }
    }
}

所以基本上,我如何让我正在展开的视图在动画发生时显示出来?

为了完整起见,这里是前向 segue 代码:

class ToScheduleFocusSegue: UIStoryboardSegue {
    override func perform() {
        let fromView = self.source.view!
        let toView = self.destination.view!
        let window = UIApplication.shared.keyWindow!
        let box = UIScreen.main.bounds
        let schedulesList = self.source as! SchedulesListController
        let cell = schedulesList.tableView.cellForRow(at: schedulesList.tableView.indexPathForSelectedRow!)!
        toView.frame = cell.convert(cell.bounds, to: window).insetBy(dx: 0, dy: 0)
        window.insertSubview(toView, aboveSubview: fromView)
        UIView.animateWithDuration(4000.milliseconds, delay: 0.seconds, options: .curveEaseInOut, animations: {
            toView.frame = box
            }) { (finished) in
                self.source.present(self.destination, animated: false, completion: nil)
        }
    }
}

(这是在XCode8中,针对iOS10使用Swift3)

【问题讨论】:

  • 您应该改用自定义过渡。 / UIPresentationController 和家族。
  • 如果你能给我看一个例子,让我朝着正确的方向前进,让我在视觉上得到我想要的,那么赏金就是你的。
  • 我会更多地研究 UICollectionView。例如,请参阅此处的“常规转换的集合视图布局动画”部分 objc.io/issues/12-animations/collectionview-animations

标签: ios swift uistoryboardsegue ios-animations


【解决方案1】:

尝试让执行演示的视图控制器也执行关闭。

所以在你放松的过程中:

UIView.animateWithDuration(4000.milliseconds, delay: 0.seconds, options: .curveEaseInOut, animations: {
        fromView.frame = targetFrame
    }) { (finished) in
        self.destination.dismiss(animated: false, completion: nil) // the destination is the one that presented the current view
    }

【讨论】:

  • 没有任何区别。我有点惊讶,我本以为会有一些不同、错误或其他差异,但视觉行为是相同的,控制台输出没有任何不同。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-02
  • 2015-08-18
  • 2014-08-11
  • 2013-10-15
相关资源
最近更新 更多