0

I am currently dealing with the screen where I have to show custom PopOver view controller to the center of the ParentViewController.

I have used PopOverView.Center = new CGPoint(UIScreen.MainScreen.Bounds.Size.Width / 2, UIScreen.MainScreen.Bounds.Size.Height / 2);

This brought the PopoverViewController to center but the Margins from all 4 sides are uneven.

NIshank
  • 97
  • 6
  • PopoverViewControllers are deprecated. Have you tried using PopoverPresentationController instead? – Saamer Jun 14 '19 at 16:28
  • Did you give your PopOverView a frame? – nevermore Jun 17 '19 at 06:14
  • @JackHua-MSFT No, is it necessary ? – NIshank Jun 17 '19 at 08:03
  • I think it is, give a PopOverView.center is not enough. – nevermore Jun 17 '19 at 08:04
  • Did your solved your problem? Share some code and maybe I can help you. – nevermore Jun 18 '19 at 05:40
  • @JackHua-MSFT No not yet. Right now I ma trying some other approach where I keep background color of Popup-VC(view controller) to be transparent and and design my popup inside a view in a Popup-VC. – NIshank Jun 18 '19 at 06:18
  • `viewController.PreferredContentSize = new CGSize(_view.Frame.Size.Width, _view.Frame.Size.Height);` `viewController.ModalPresentationStyle = UIModalPresentationStyle.Popover;` – NIshank Jun 18 '19 at 06:19
  • @NIshank How do you popup the viewController? PresenetViewController? Add a subViewController? – nevermore Jun 18 '19 at 06:44
  • `Popover.ContentViewController = viewController;` `Popover.PresentFromRect(CGRect.Empty, _view, UIPopoverArrowDirection.Any, true);` @JackHua-MSFT – NIshank Jun 18 '19 at 07:17
  • The last approach worked for me. Thanks for the help. – NIshank Jun 18 '19 at 07:18
  • What is Popover here? I wonder why not just popup a custom View instead of a ViewController? – nevermore Jun 18 '19 at 07:18
  • I also thought the the but can't do in my current project as old UI was made using [Fluent](https://github.com/FluentLayout/Cirrious.FluentLayout) and it was scrapped and again refreshed through storyboards, so there was very less scope of customization as classes were tightly bound. – NIshank Jun 18 '19 at 07:21

1 Answers1

0

PopoverViewControllers are deprecated. Have you tried using PopoverPresentationControllers instead, they are centred by default? There are several examples here

Saamer
  • 4,687
  • 1
  • 13
  • 55