UIPasteControl sometimes disappear

Problem

  • Our app use UIPasteControl for people taps to place pasteboard contents in UITextView.
  • It worked fine at first, but recently received a lot of user feedback and the button suddenly disappeared
  • This problem usually occurs when an App switches between the front and back

More Information

  1. When the button disappears, we find that the child view of the UIPasteControl control which name _UISlotView has a size of zero.

  2. we use UIKit and AutoLayout,limit button size (100, 36)

let config = UIPasteControl.Configuration()
config.displayMode = .labelOnly
config.cornerStyle = .fixed
config.baseForegroundColor = .white
config.baseBackgroundColor = .black
config.cornerRadius = 18
let btn = UIPasteControl(configuration: config)
pasteBtn = btn
addSubview(pasteBtn)

pasteBtn.snp.makeConstraints { make in
  make.trailing.equalTo(-20)
  make.bottom.equalTo(-10)
  make.size.equalTo(CGSize(width: 100, height: 36))
}

UI view information

<UIPasteControl: 0x107dda810; frame = (0 0; 100 36); layer = <CALayer: 0x3010ff000>>

(lldb) po [0x107dda810 subviews]
<__NSSingleObjectArrayI 0x30152ff00>(
<_UISlotView: 0x107dea630; frame = (0 0; 100 36); userInteractionEnabled = NO; layer = <CALayer: 0x3010eb460>>
)

anyone meet before? is there a workaround?

If a paste control detects that it needs more space than it was given to display its content, it will disable itself, which may be what is happening here.

You can test this hypothesis in the debugger by calling sizeThatFits: on the paste control and seeing what size it believes it requires.

Add info:

After the App enter inactive, the user does some clipboard-related actions, such as copying new content.Then go back to the App, click the button and it will behave differently.

  1. The state of the button is disable, actually the clipboard should have content and we expect the button should be highlighted
  2. Button click behavior exception, will still show clipboard permissions alert

Workaround:

re-set UIPasteControl target when app enter active, like UIApplication.didBecomeActiveNotification.

it work for me

I have the same problem. In my case UIPasteButton is inside the collection view cell and it disappears sometimes (and sometimes it works fine). I try to make it static, re-assign target, recreate when cell appears, but haven’t found 100% working solution. Need help from Apple engineers

I'm encountering the same issue. During the process of switching the app between the foreground and the background, the UIPasteControl occasionally disappears. However, it can be displayed normally again after restarting the app. What could be the reason for this? Is there any solution?

Add Info

I try to [po pasteBtn] when paste control did clear, but I am very sad that no solution can be found at present.

<UIPasteControl: 0x107dda510; frame = (0 0; 100 40); layer = <CALayer: 0x3010ff300>>

<_UISlotView: 0x1377d2600; frame = (50 20; 0 0); alpha = 0.25; userInteractionEnabled = NO; layer = <CALayer: 0x303128d20>>

the result of sizeThatFits={0, 0}

Need help from Apple engineers +1

UIPasteControl sometimes disappear
 
 
Q