gpt4 book ai didi

ios - UIStackView Peek 和 Pop 覆盖故障

转载 作者:行者123 更新时间:2023-12-01 19:56:17 25 4
gpt4 key购买 nike

我正在尝试使用 UIStackView 的内容实现 Peek 和 Pop .问题是浅压期间的覆盖(未模糊的部分)不包含正确的内容。它在正确的位置,因为它就在我手指的正下方,但内容似乎来自 View 中的其他地方:example

重现步骤:

  • 使用 Storyboard打开一个空的 iOS 项目
  • 添加 UIStackView到 View Controller 的 View
  • 从堆栈 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 中的错误?

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

    最佳答案

    更换

    registerForPreviewing(with: self, sourceView: stackView)

    经过
    registerForPreviewing(with: self, sourceView: view)

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

    关于ios - UIStackView Peek 和 Pop 覆盖故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42506617/

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