Изменение размера UIModalPresentationFormSheet на iOS 8

Я пытаюсь изменить размер UIViewController, представленный как модальный на iPad, используя UIModalPresentationFormSheet, и хотя я получил его работу над <= iOS 7, я не могу на iOS 8

Ответы

Ответ 1

Для iOS 8 вам необходимо установить свойство preferredContentSize, но для iOS 7 и старше вы должны установить свойство superiew.frame.

Пример кода:

UIViewController* modalController = [[UIViewController alloc]init];
modalController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
modalController.modalPresentationStyle =  UIModalPresentationFormSheet;

CGPoint frameSize = CGPointMake([[UIScreen mainScreen] bounds].size.width*0.95f, [[UIScreen mainScreen] bounds].size.height*0.95f);
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;

// Resizing for iOS 8
modalController.preferredContentSize = CGSizeMake(frameSize.x, frameSize.y); 
// Resizing for <= iOS 7
modalController.view.superview.frame = CGRectMake((screenWidth - frameSize.x)/2, (screenHeight - frameSize.y)/2, frameSize.x, frameSize.y);

UIViewController *vc = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
[vc presentViewController:modalController animated:YES completion:nil];

Ответ 2

Это зависит от того, используете ли вы UIPopoverPresentationController или UIPresentationController. Вы можете попробовать установить свойство preferredContentSize для вашего нового размера контента (свойство contentSizeForViewInPopover устарело в iOS 8).

Ответ 3

Чтобы изменить размер представления UIViewController, когда он уже представлен стилем UIModalPresentationFormSheet модального представления и отображается, используйте для iOS 8 +:

self.preferredContentSize = CGSizeMake(width, height);

[UIView animateWithDuration:0.25 animations:^{
    [self.presentationController.containerView setNeedsLayout];
    [self.presentationController.containerView layoutIfNeeded];
}];