As far as I understand your question, I want to offer a simple solution for this:
I used Viewcontroller and PopoverView in the storyboard. The viewcontroller will work as the main view controller, where the PopoverView will work as displayed as a popover. . (Note: Remember to set the Explicit Content Size for the PopoverView in the storyboard) for an additional link, you can see the attached screenshot of my storyboard

Here is an example of the source code of the ViewController, in which you find the position of the Popoverview will change in accordance with the right to change the frame button.
This code is developed using Objective-C
ViewController.h
// // ViewController.h // SOPopoverControllerDemo // // Created by Test User on 08/01/18. // Copyright Β© 2018 Test User All rights reserved. // #import <UIKit/UIKit.h> @interface ViewController : UIViewController @end
ViewController.m
// // ViewController.m // SOPopoverControllerDemo // // Created by Test User on 08/01/18. // Copyright Β© 2018 Test User All rights reserved. // #import "ViewController.h" @interface ViewController () <UIPopoverPresentationControllerDelegate> @property (weak, nonatomic) IBOutlet UIBarButtonItem *leftToolBarBtn; @property (weak, nonatomic) IBOutlet UIBarButtonItem *rightToolBarBtn; @property (weak, nonatomic) IBOutlet UIBarButtonItem *flexibleBtn; @property (weak, nonatomic) IBOutlet UIToolbar *bottomToolBar; @property (weak,nonatomic) UIPopoverPresentationController *popOverController; @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. if (self.view.frame.size.width > self.view.frame.size.height) { self.rightToolBarBtn.width = 200; self.leftToolBarBtn.width = 200; } else { self.rightToolBarBtn.width = 150; self.leftToolBarBtn.width = 150; } } - (void) viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator { [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) { if (size.width > size.height) { _rightToolBarBtn.width = 200; [self dismissViewControllerAnimated:true completion:nil]; [self rightToolBarBtnTapped:_rightToolBarBtn]; } else { _rightToolBarBtn.width = 150; [self dismissViewControllerAnimated:true completion:nil]; [self rightToolBarBtnTapped:_rightToolBarBtn]; } } completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) { }]; } - (IBAction)rightToolBarBtnTapped:(id)sender { //Grab the controller for popover UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UIViewController *controller = [storyboard instantiateViewControllerWithIdentifier:@"PopoverView"]; if (self.view.frame.size.width > self.view.frame.size.height ) { controller.preferredContentSize = CGSizeMake(200, 100); } else { controller.preferredContentSize = CGSizeMake(150, 100); } controller.modalPresentationStyle = UIModalPresentationPopover; [self presentViewController:controller animated:YES completion:nil]; // configure the Popover presentation controller _popOverController = [controller popoverPresentationController]; _popOverController.delegate = self; _popOverController.permittedArrowDirections = UIPopoverArrowDirectionUp; _popOverController.barButtonItem = self.rightToolBarBtn; } //-------------------------------------------------- #pragma mark -> UIPopOverController Delegate //-------------------------------------------------- - (BOOL)popoverPresentationControllerShouldDismissPopover:(UIPopoverPresentationController *)popoverPresentationController { return YES; } - (void)popoverPresentationControllerDidDismissPopover:(UIPopoverPresentationController *)popoverPresentationController { NSLog(@"Popover Did Dismissed"); } @end
Popoverview.h
// // PopoverView.h // SOPopoverControllerDemo // // Created by Test User on 08/01/18. // Copyright Β© 2018 Test User All rights reserved. // #import <UIKit/UIKit.h> @interface PopoverView : UIViewController @end
PopoverView.m
// // PopoverView.m // SOPopoverControllerDemo // // Created by Test User on 08/01/18. // Copyright Β© 2018 Test User All rights reserved. // #import "PopoverView.h" @interface PopoverView () @end @implementation PopoverView - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
source share