我正在使用带有按钮的cardView动画翻转作为其子视图以及其他视图。动画以及图像/文本在模拟器/设备/调试器中正确显示。
问题在于水龙头区域 - 在对角处识别翻转按钮水龙头后。任何人都可以建议我为什么会遇到这个问题?谢谢!
动画代码发布在下面,使用调试器检查按钮约束,它们是正确的。
fileprivate func flippingHandler(forView view: UIView) {
guard let cardContentView = view.subviews.first(where: { $0 is CardContentView} ) as? CardContentView,
let initialCardView = cardContentView.snapshotView(afterScreenUpdates: false) else {
return
}
swipeableView.isUserInteractionEnabled = false
initialCardView.tag = Default.snapshotTag
cardContentView.updateForRotation()
cardContentView.superview?.addSubview(initialCardView)
setupCATrasaction(forInitialView: initialCardView, finalView: cardContentView)
}
//MARK: - Helpers
fileprivate func setupCATrasaction(forInitialView initialView: UIView, finalView: CardContentView) {
CATransaction.begin()
CATransaction.setAnimationDuration(Default.rotationDuration)
CATransaction.setCompletionBlock { [weak self] in
self?.cardRotationCompletionHandler(forView: finalView)
}
setupInitialCardLayer(initialView.layer)
setupFinalCardLayer(finalView.layer)
CATransaction.commit()
}
fileprivate func cardRotationCompletionHandler(forView cardContentView: CardContentView) {
cardContentView.superview?.subviews.filter { $0.tag == Default.snapshotTag }.forEach { $0.removeFromSuperview() }
swipeableView.isUserInteractionEnabled = true
}
fileprivate func setupInitialCardLayer(_ startingLayer: CALayer) {
startingLayer.isDoubleSided = false
startingLayer.add(scalingAnimation, forKey: "scale")
startingLayer.add(flipAnimation, forKey: "flipAnimation")
}
fileprivate func setupFinalCardLayer(_ finalLayer: CALayer) {
finalLayer.isDoubleSided = false
finalLayer.transform = CATransform3DMakeRotation(CGFloat(Double.pi), 0, 1, 0)
finalLayer.add(scalingAnimation, forKey: "scale")
finalLayer.add(flipAnimation, forKey: "flipAnimation")
}
答案 0 :(得分:0)
我能够通过丢弃所有卡片视图并在动画完成后从头开始再次加载它们来解决此问题。
希望此解决方案能够帮助解决类似问题的人。
见下面的代码:
fileprivate func cardRotationCompletionHandler(forView cardContentView: CardContentView) {
cardContentView.superview?.subviews.filter { $0.tag == Default.snapshotTag }.forEach { $0.removeFromSuperview() }
swipeableView.isUserInteractionEnabled = true
refreshCardViews()
}
fileprivate func refreshCardViews() {
guard !cards.isEmpty else {
return
}
//updates relevant models before refresh
cards.forEach { $0.wasShown = false }
swipeableView.numberOfActiveView = cards.count > Default.maxNumberOfCards ? Default.maxNumberOfCards : UInt(cards.count)
//removes all card views from superview
swipeableView.discardViews()
//loads all views again
swipeableView.loadViews()
}