gpt4 book ai didi

ios - 翻转 super View 后 UIButton 点击​​区域发生移动

转载 作者:行者123 更新时间:2023-11-30 11:30:05 26 4
gpt4 key购买 nike

我正在使用带有按钮的cardView 的动画翻转,因为它是与其他 View 一起的 subview 。动画以及图像/文本在模拟器/设备/调试器中正确显示。

问题出在点击区域 - 翻转按钮点击后在对角被识别。谁能建议我为什么会遇到这个问题?谢谢!

下面发布了动画代码,使用调试器检查按钮约束并且它们是正确的。

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")
}

最佳答案

我能够通过丢弃所有卡片 View 并在动画完成后从头开始重新加载它们来解决此问题。

希望这个解决方案能够帮助有人解决类似的问题。

参见下面的代码:

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()
}

关于ios - 翻转 super View 后 UIButton 点击​​区域发生移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50345481/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com