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

UIPasteControl sometimes disappear
 
 
Q