UIPasteControl still asks for permission when it's not the first one on the screen.

I'm trying to tame UIPasteControl on the screen where I have multiple textfields and each is having a paste button.

To comply with iOS 16 I'm changing my buttons to UIPasteControl.

This is a storyboard based UIKit screen with a controller written in swift.

I added UIPasteControl #1 with target of a textfield above it, and it works as expected.

I added UIPasteControl #2 with target of a textfield above it, and when I tap on that second UIPasteControl, it asks for the permission, per image attached.

I'm quite confused and I have double checked everything for my own error. Everything looks alright, except for that second UIPasteControl raising this permission popup. The first UIPasteControl never raises the popup.

This is on a real device running iOS 16 RC, Xcode Version 14.0 (14A309).

What I can be missing? What I can try?

Replies

The UIPasteControl is sensitive to items being drawn close to it. Best to try moving it away from the two text fields. If you still get this alert, please submit a minimal project that demonstrates the alert via FBA. Thanks!

glow

Thank you glow!

Indeed. This would explain the problems I'm seeing. I redesigned the screen to only have one Paste control on it and it is placed in the dedicated cell with only a help label below it. Even when sizing that dedicated UIPasteControl - until it stopped "touching" the neighbour controls, it was asking for the permission. I can see the point in avoiding obscuring its parts.

How can we define the UIPasteControl sizing requirements properly to be sure to give it enough space? I'm trying its intrinsic size and it always returns as zero rect. I'm trying to achieve its size predictability via minimumContentSizeCategory and maximumContentSizeCategory, so it has a predictable size for the different accessibility text sizes.

What's the correct way of placing/sizing this control in a storyboard with auto layout?

The example here:

https://developer.apple.com/documentation/uikit/uipastecontrol?changes=_5

Suggests:

pasteButton.frame = CGRect(x: view.bounds.width/2.0, y: view.bounds.height/2.0, width: 150, height: 60)

Is it something considered the safe dimensions for the UIPasteControl for all of the accessibility text sizes? Width of 150 doesn't seem to be "safe" - the whole UIPasteControl may not be even shown or it might be raising the permission alert, if the control itself shows.

Is it something that needs to be embedded into SwiftUI? Or would it work well in some sort of a container like UIStackView, would this one size it properly for all of the accessibility text sizes?

Some pointers would be appreciated so we can build future-proof designs that would not break easily.

Testing this control was exhausting because I couldn't predict the results. Combining it with the original UI was an even more complicated issue.

I really wanted a permission control like Photo Library.

UIPasteControl does have intrinsicContentSize but this starts out at size zero and then updates asynchronously to its final value, due to the design of the control. Autolayout then adapts all its dependent controls appropriately.

You will get best results if you do not force its actual size to smaller than intrinsic content size, so e.g. constraining the center only to something else, or constraining the width to some larger value. That being said, it will allow for a little squeezing.

If you want to embed this in SwiftUI, use PasteButton instead which is backed by UIPasteControl.

glow

  • I'm using UIPasteControl in a collection view, with its width constrained to 44.0f (icon only). This seems to work fine, however for one beta tester the UIPasteControl is not appearing. I've yet to log whether it exists but is not showing for some (private?) reason. The strange thing is that his device (iPhone 12 Pro Max, iOS 16.4.1) is the only one with this issue, while all other testers see the UIPasteControl just fine (including me with iPhone XS Max, 16.4.1). TIA for any insight!

Add a Comment