3

我正在尝试实现出现在屏幕底部的铅笔工具包(一条铅笔、橡皮擦等)。但是,在运行这行代码时:

guard let window = view.window, let toolPicker = PKToolPicker.shared(for: window)
else {return}

我在日志中收到以下错误,并且工具选择器没有出现:

    PDF Reader[926:85385] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x60000191d450 UIView:0x7fdfb7376ff0.height == 75   (active)>",
    "<NSLayoutConstraint:0x60000191d4a0 V:|-(0)-[UIView:0x7fdfb7376ff0]   (active, names: '|':PKPaletteContainerView:0x7fdfb737b7e0 )>",
    "<NSLayoutConstraint:0x60000191dae0 V:|-(0)-[PKPaletteContainerView:0x7fdfb737b7e0]   (active, names: '|':UIView:0x7fdfb46181d0 )>",
    "<NSLayoutConstraint:0x60000191dc70 PKPaletteContainerView:0x7fdfb737b7e0.bottom == UIView:0x7fdfb46181d0.bottom   (active)>",
    "<NSLayoutConstraint:0x600001901ea0 V:|-(0)-[UIView:0x7fdfb46181d0]   (active, names: '|':PKPaletteView:0x7fdfb462d3e0 )>",
    "<NSLayoutConstraint:0x600001901ef0 UIView:0x7fdfb46181d0.bottom == PKPaletteView:0x7fdfb462d3e0.bottom   (active)>",
    "<NSLayoutConstraint:0x6000019fcf00 PKPaletteView:0x7fdfb462d3e0.height == 122   (active)>",
    "<NSLayoutConstraint:0x60000191d720 UIView:0x7fdfb7376ff0.bottom == PKPaletteContainerView:0x7fdfb737b7e0.bottom   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x60000191d450 UIView:0x7fdfb7376ff0.height == 75   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.

我不确定如何处理 PKPalette 的约束或下面的哪些约束冲突。我也尝试禁用 translatesAutoResizingMaskIntoConstraints 并且它不起作用,因为我的应用程序的其他部分依赖它。任何帮助表示赞赏,谢谢!

4

3 回答 3

1

在 iPhone 上调用 PKToolPicker 时,我收到相同的日志消息。在 iPad 上,我没有收到约束错误。如果我查看约束冲突,这一切似乎都是 PKToolPicker 内部的,与我的布局设置无关。

如果您运行相同的代码,但 iPhone 是横向而不是纵向,则不会发生冲突。因此,我怀疑 PKPickerTool 约束具有某种限制,当屏幕宽度太窄时,Apple 需要修复这些限制。我会发布一个雷达。

于 2020-03-18T01:45:37.623 回答
0

这不是因为限制;你需要调用这些行:

toolPicker.setVisible(true, forFirstResponder: canvasView)
canvasView.becomeFirstResponder()

您可以在此处找到更多信息:

https://developer.apple.com/documentation/pencilkit/drawing_with_pencilkit https://developer.apple.com/videos/play/wwdc2019/221/

于 2020-01-30T06:32:35.743 回答
0

我也有同样的情况。如果设置布局断点,我可以看到涉及的视图都是苹果自己的,它们甚至存在于私有覆盖窗口中,而不是主窗口。所以似乎是框架中的一个合法错误。

我发现对我来说,第一次尝试获取工具时它会失败。为了解决这个问题,我现在只需在发布后很早就获得这些工具。我不使用它们,但这会触发错误,因此当我真正需要这些工具时,它们会起作用。

if #available(iOS 13.0, *) {
    PKToolPicker.shared(for: view.window!)
}
于 2021-06-10T09:42:12.390 回答