IOS 11 Problem With Release Of Popover In Multitasking

Keeping popover open. Then, when I try to switch to 2/3 screen mode and reposition the center of the BarButtonItem with the fixed space of the BarButtonItem in viewWillTrainsition, my tooltip moves to the previous location of barButtonItem.

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator { [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) { if (size.width>size.height) { _fixedSpace.width = 280; } else { _fixedSpace.width = 80; } } completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) { }];} 

enter image description here

+5
source share
3 answers

I reproduced the same script, and I found a fix for this, as shown below:

 [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) { if (size.width > size.height) { fixedSpace.width = 280; } else { fixedSpace.width = 80; } } completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) { CGRect rect = [self.view convertRect:barBtn.frame fromView:barBtn]; popover.sourceRect = rect; }]; 

Try resetting the sourceRect property in the completion block.

Hope this will be helpful!

0
source

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

enter image description here

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 
0
source

From iOS11, the control panel element uses a restriction instead of frames. Therefore, try to limit each element of the button. It may not be displayed visually, but it plays an important role in creating this kind of problem.

Try using the code below to set a limit:

 if #available(iOS 11.0, *) { _fixedSpace.widthAnchor.constraint(equalToConstant: 280.0).isActive = true } 

Hope this helps!

-1
source

Source: https://habr.com/ru/post/1273726/


All Articles