0

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).

ablyth
  • 1
  • 2
  • Please read [ask] before posting. This is just paragraphs of dense text with no relevant code included, no images illustrating the problem you're having, and no concise question that you want answered. – Jason Nov 16 '22 at 15:12
  • @Jason I have explained what I've tried with both the expected and actual outcomes. I have included an image where relevant to show the visual artifact. The code I have created is a 1 to 1 translation of the linked github (swift) in Xamarin.iOS. My issues are explained and my question is how do I create a popover which animates its resizing and offsets the contained View in accordance to the selected popover arrow direction. I have found no other examples of people addressing these issues I am having. – ablyth Nov 16 '22 at 15:21
  • Could you provide the Xamarin.iOS code on which you create the popover and resize it? About animate the transition, you can refer to [the official documentation of Xamarin.](https://learn.microsoft.com/en-us/xamarin/ios/platform/graphics-animation-ios/core-animation#view-transitions). – Zack Nov 18 '22 at 07:53

0 Answers0