我正在尝试使用UIStackView
的内容实现Peek和Pop。问题是浅压期间的覆盖层(未模糊的部分)没有包含正确的内容。它位于正确的位置,因为它就在我的手指下面,但是内容似乎是从视图中的其他位置获取的:
重现步骤:
UIStackView
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/