1

我正在尝试使用UIStackView. 问题是浅压期间的覆盖(未模糊的部分)不包含正确的内容。它在正确的位置,因为它就在我手指的正下方,但内容似乎是从视图中的其他地方获取的:例子

重现步骤:

  1. 使用情节提要打开一个空的 iOS 项目
  2. UIStackView在视图控制器的视图中添加一个
  3. 从堆栈视图的所有四个侧面添加最近邻居约束等于0
  4. 将 的内容替换为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)
        }
    }
    
  5. 在您的(物理)设备上运行应用程序并在任何地方强制触摸

我做错了什么,或者这是 UIKit 中的错误?

编辑:这就是我期望它的行为方式:例子

4

1 回答 1

2

更换

registerForPreviewing(with: self, sourceView: stackView)

经过

registerForPreviewing(with: self, sourceView: view)

解决了这个问题。我仍然怀疑这是一个错误,但至少这是一种解决方法。

于 2017-03-01T10:31:43.860 回答