Search code examples
sizeorientationuiimagepickercontrolleruipopovercontroller

Can't set size of UIPopoverController on device rotation change


In my iPad app, I am recording a video (UIImagePickerController in a UIPopoverController).

The problem is that when I change the orientation of the device, the size of the UIPopoverController reduces to 320x480 (for portrait) and 480x320 (for landscape). Surprisingly, the exact same dimensions (600x880) are working fine when I create it, but not when I rotate it.

Here is how I am initializing:

self.popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
popover.delegate = self;
if ([[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationPortrait || [[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationPortraitUpsideDown) {
    [self.popover presentPopoverFromRect:CGRectMake(109, 590, 550,500) inView:self.view permittedArrowDirections:0 animated:YES];//recordProtocolBtn.frame
    [self.popover setPopoverContentSize:CGSizeMake(600, 880)];
}
else {
    [self.popover presentPopoverFromRect:CGRectMake(750, 110, 550, 600) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
    [self.popover setPopoverContentSize:CGSizeMake(600, 600)];
}

In rotation to Portrait:

[self.popover dismissPopoverAnimated:NO];
[self.popover presentPopoverFromRect:CGRectMake(109, 590, 550,500) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
[self.popover setPopoverContentSize:CGSizeMake(600, 880)];

And in rotation to landscape:

[self.popover dismissPopoverAnimated:NO];
[self.popover presentPopoverFromRect:CGRectMake(750, 110, 550, 600) inView:self.view permittedArrowDirections:0 animated:YES];
[self.popover setPopoverContentSize:CGSizeMake(600, 600)];

Solution

  • What I did is not strictly a solution but a workaround.

    I disabled the orientation change notifications from firing when I presented the UIPopoverController and enabled them when I dismissed it, using help from this answer.

    This way the app works smoothly because I think the users won't like the app to rotate during video recording.