我正在尝试使用 UIStackView
的内容实现 Peek 和 Pop .问题是浅压期间的覆盖(未模糊的部分)不包含正确的内容。它在正确的位置,因为它就在我手指的正下方,但内容似乎来自 View 中的其他地方:
重现步骤:
UIStackView
到 View Controller 的 View 0
ViewController.swift
的内容使用以下代码:import UIKit
class ViewController: UIViewController {
@IBOutlet var stackView: UIStackView!
override func viewDidLoad() {
super.viewDidLoad()
registerForPreviewing(with: self, sourceView: stackView)
let loremIpsum = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus sed feugiat ligula. Sed in rutrum lacus, vel auctor felis. Vivamus molestie felis nisi. Mauris euismod eros vitae libero commodo porttitor. Nam posuere, dui vitae aliquam mollis, quam mauris tempus turpis."
let label = UILabel()
label.numberOfLines = 0
label.text = repeatElement(loremIpsum, count: 4).joined(separator: "\n\n")
stackView.addArrangedSubview(label)
}
}
extension ViewController: UIViewControllerPreviewingDelegate {
func previewingContext(_ previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? {
previewingContext.sourceRect = CGRect(x: location.x - 50, y: location.y - 50, width: 100, height: 100)
return storyboard?.instantiateInitialViewController()
}
func previewingContext(_ previewingContext: UIViewControllerPreviewing, commit viewControllerToCommit: UIViewController) {
present(viewControllerToCommit, animated: true)
}
}
我做错了什么,或者这是 UIKit 中的错误?
编辑:这就是我期望它的行为方式:
最佳答案
更换
registerForPreviewing(with: self, sourceView: stackView)
经过
registerForPreviewing(with: self, sourceView: view)
解决了这个问题。我仍然怀疑这是一个错误,但至少这是一种解决方法。
关于ios - UIStackView Peek 和 Pop 覆盖故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42506617/