Presenting UIViewController as Popover has numerous issues, am I doing it wrong?

75 views Asked by At

I am using C# Xamarin.iOS and working on an iOS application (designed for iPad only). I currently only have approximately 6 months of C#/Xamarin experience so apologies in advance. I am noticing various problems embedded in the default implementation of UIPopoverPresentationController classes. At this point I cannot tell if I am just implementing them unbelievably wrong or if there are fundamental flaws in popovers.

I am finding it difficult having to go so far out of the way to implement what I presumed would be basic functionality of Popovers.

  1. Popover content size and position:

What I tried: Implementing a UIViewController with UIModalPresentationStyle.Popover.

What I expected: The specified PreferredContentSize to reflect the size of the content within the Popover UI.

What actually happened: The UIView content has its height/width increased by 13 along the axis of the popover arrow direction to account for the extra size of the arrow - PreferredContentSize acts as a baseline to which the extra is added, the result is that views are not positioned as intended nor are any actual offsets accounting for the arrow applied by default.

There are ways I have found to fix this, such as subclassing UIViewController to implement logic within the ViewWillAppear method to manually re-set the size of the View content to the desired size, and simultaneously reset and create new constraints to account for the offset required by the arrow. However, this surely cannot be the intended way?

  1. Popover resizing:

What I tried: I implemented the test case described here in C# Xamarin.iOS: (https://github.com/noahsark769/NGPopoverForceResizeTest/blob/master/NGPopoverForceResizeTest/ViewController.swift)

What I expected: The popover should resize and animate the transition between sizes.

What actually happened: The popover does resize, but the animations are not complete - size increases are animated, but size decreases are not.

It is very frustrating that the increase in size is animated but the decrease in size is not. Following the link there are several gifs which show the animation of both increase and decrease of size, but I am unable to recreate this without visual artifacts (see attached image). Image showing transparency visual artifact on height decrease

The transparency is the result of the shadow image (is there a reason it is an image anyway?) which does animate the change in size, whereas the Views themselves do not animate and simply snap to the new size.

I have tried replacing the popover shadow image with an identical image with a filled in (non-transparent) centre and using the UIImage.CreateResizableImage(insets, mode) method to create a new resizable image, unfortunately all inset combinations I attempt only appear to affect the shadow (unlike the visual artifact in the attached image, which represents the centre portion of the shadow image which reflects the popover background/size resizing).

I tried simply hiding/removing the shadow image/layer and using the Layer.Shadow options on one of the other views which collectively create the Popover to create an identical shadow, but this removes the smooth animation between heights (which is perhaps only created by the shadow image being resized).

0

There are 0 answers