I developed an application for iOS7 and am now trying to update it for iOS8. The problem I have is the following:
The orientation of the application screen can be rotated, and in some cases several buttons move sharply. I have several popovers that point to these buttons, so if the popup is open when the screen rotates, the button moves, I also need a popover.
In iOS7, I did the following: When the screen is rotated, I updated the restrictions
- (void) updateViewConstraints { if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) { self.Button.constant = (CGFloat)10; } else { self.Button.constant = (CGFloat)5; } [super updateViewConstraints]; }
I also move popover
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{ if(TempDisplayPopoverController == examplePopoverController) { [examplePopoverController presentPopoverFromRect:[self ExamplePopoverPosition] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; } }
I initially download popover
- (void) LoadPopover{ examplePopover = [[examplep alloc] initWithNibName:@"exampleP" bundle:nil]; [examplePopover setDelegate:self]; examplePopoverController = [[UIPopoverController alloc] initWithContentViewController: examplePopover]; [examplePopoverController setDelegate:self]; examplePopoverController.popoverContentSize = examplePopover.view.frame.size; TempDisplayPopoverController = examplePopoverController; if ([examplePopoverController isPopoverVisible]) { [examplePopoverController dismissPopoverAnimated:YES]; } else { [examplePopoverController presentPopoverFromRect:[self ExamplePopoverPosition] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; } }
[self ExamplePopoverPosition] just returns the position of the button.
It all worked great, I was happy, the iPad was happy and everything behaved.
Now because of iOS8, I need to change a few bits.
self.interfaceOrientation depreciates
[examplePopoverController presentPopoverFromRect:[self ExamplePopoverPosition] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
in didRotateFromInterfaceOrientation throws an error
"Application tried to represent an active popover presentation: <UIPopoverPresentationController: 0x7bf59280>"
I managed to fix self.interfaceOrientation
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { [self SetUpScreen:toInterfaceOrientation]; } - (void) SetUpScreen:(UIInterfaceOrientation)toInterfaceOrientation{ if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) { self.Button.constant = (CGFloat)10; } else { self.Button.constant = (CGFloat)5; } [super updateViewConstraints]; }
but I have no idea how to solve the problem with popover. I tried
popoverController: willRepositionPopoverToRect: inView:
but it just can't seem like it works.
Can anyone advise
thanks