[英]UIStackView Peek and Pop overlay glitch
I'm trying to implement Peek and Pop with the contents of a UIStackView
. 我正在尝试使用UIStackView
的内容实现Peek和Pop。 The problem is that the overlay (the part that isn't blurred) during the shallow press doesn't contain the right contents. 问题是浅压期间的覆盖层(未模糊的部分)没有包含正确的内容。 It's in the right place, since it's right below my finger, but the contents seem to be taken from elsewhere in the view: 它在正确的位置,因为它就在我的手指下面,但是内容似乎是从视图的其他地方获取的:
Steps to reproduce: 重现步骤:
UIStackView
to the view controller's view 将UIStackView
添加到视图控制器的视图 0
从堆栈视图的所有四个侧面添加最近的邻居约束,等于0
Replace the contents of ViewController.swift
with the following code: 用以下代码替换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) } }
Run the app on your (physical) device and force touch anywhere 在您的(物理)设备上运行该应用,然后在任何地方强制触摸
Am I doing something wrong, or is this a bug in UIKit? 我是在做错什么,还是UIKit中的错误?
Replacing 更换
registerForPreviewing(with: self, sourceView: stackView)
by 通过
registerForPreviewing(with: self, sourceView: view)
solved the problem. 解决了问题。 I still suspect that it's a bug, but at least this is a workaround. 我仍然怀疑这是一个错误,但是至少这是一种解决方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.