why preferredContentSize doesn't work when presenting UIViewController with PresentationStyle = .formSheet

55 Views Asked by At

I just try to test the preferredContentSize effect with code below:

let vc = CustomViewController()
vc.modalPresentationStyle = .formSheet
self.preferredContentSize = CGSize(width:50, height: 50)
self.present(vc, animated: true)

But it seems that the preferredContentSize property doesn't work at all. I can definitely sure that "CustomViewController" have no side effect on this problem because it's an empty UIViewController subclass.

According to the official docs:

In a regular-width, regular-height size class, the system adds a dimming layer over the background content and centers the view controller’s content on top of this layer. The default content size is smaller than that of the UIModalPresentationStyle.pageSheet style. A part of the background content always remains visible. To provide a custom content size, use the modal view controller’s preferredContentSize property.

I've found a lot of similar questions, but nearly all of them are about presenting with popover. My question is whether preferredContentSize only works with .popover style, or .formSheet style either.

And if it works with .formSheet style presentation, what's wrong with my code? Any clue will be appreciated.

0

There are 0 best solutions below