В iOS8 Вы не должны менять SuperView границы в viewWillLayoutSubviews, поскольку он вызывает бесконечный цикл.
EDIT: в собственности iOS8 preferredContentSize хорошо работает.
Вы должны изменить свой код таким образом:
UserLoginViewController *loginVC = [[UserLoginViewController alloc] initWithNibName:@"UserLoginViewController" bundle:nil];
loginVC.modalPresentationStyle = UIModalPresentationFormSheet;
loginVC.delegate = self;
if(IS_IOS8)
{
loginVC.preferredContentSize = CGSizeMake(300, 250);
}
[self presentViewController:loginVC animated:YES completion:nil];
Редактирование просмотра границ -
- (void)viewWillLayoutSubviews{
[super viewWillLayoutSubviews];
self.view.superview.layer.cornerRadius = 10.0;
self.view.superview.layer.masksToBounds = YES;
if(!IS_IOS8)
{
self.view.superview.bounds = CGRectMake(0, 0, 300, 250);
}
}
Другой способ, который дает вам больше возможностей настройки заключается в использовании UIPresentationController и UIViewControllerTransitioningDelegate. Взгляните на мой код ниже.
родительский контроллер вид:
_aboutViewController = [[AboutViewController alloc] init];
_aboutViewController.modalPresentationStyle = UIModalPresentationFormSheet;
if(IS_IOS8)
{
if(aboutTransitioningDelegate == nil)
{
aboutTransitioningDelegate = [[AboutTransitioningDelegate alloc] init];
}
_aboutViewController.transitioningDelegate = aboutTransitioningDelegate;
_aboutViewController.modalPresentationStyle = UIModalPresentationCustom;
}
[self presentViewController:_aboutViewController animated:YES completion:nil];
AboutViewController.m
#import "AboutViewController.h"
@interface AboutViewController()
@end
@implementation AboutViewController
- (void)viewWillLayoutSubviews{
[super viewWillLayoutSubviews];
if(IS_IOS8)
{
return;
}
CGSize displaySize = CGSizeMake(320, 462);
self.view.superview.bounds = CGRectMake(0, 0, displaySize.width, displaySize.height);
}
@end
AboutTransitioningDelegate.h:
@interface AboutTransitioningDelegate : NSObject <UIViewControllerTransitioningDelegate>
@end
AboutTransitioningDelegate.m:
#import "AboutTransitioningDelegate.h"
#import "AboutPresentationController.h"
@implementation AboutTransitioningDelegate
-(UIPresentationController *)presentationControllerForPresentedViewController:(UIViewController *)presented presentingViewController:(UIViewController *)presenting sourceViewController:(UIViewController *)source
{
return [[AboutPresentationController alloc] initWithPresentedViewController:presented presentingViewController:presenting];
}
@end
AboutPresentationController.h
#import <UIKit/UIKit.h>
@interface AboutPresentationController : UIPresentationController
@end
AboutPresentationController.m
#import "AboutPresentationController.h"
@implementation AboutPresentationController
-(CGRect)frameOfPresentedViewInContainerView
{
CGSize displaySize = CGSizeMake(320, 462);
if([[Config sharedInstance] latestVersionFromAppstoreInstalled])
{
displaySize = CGSizeMake(320, 416);
}
CGRect r = CGRectZero;
r.size = displaySize;
r.origin.y = self.containerView.bounds.size.height/2 - displaySize.height/2;
r.origin.x = self.containerView.bounds.size.width/2 - displaySize.width/2;
return r;
}
-(void)containerViewWillLayoutSubviews
{
[super containerViewWillLayoutSubviews];
self.presentedView.frame = [self frameOfPresentedViewInContainerView];
}
@end
Имя_проекта-префикс.пч
#define IS_IOS8 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8)
Так же нужно добавить вместе с моим старым кодом, этот код? iOS 7 не включал это, поэтому мне нужно было бы сказать: «Если iOS 8, используйте UIPresentationController, иначе отредактируйте супервизор? Правильно? Кажется, субоптимально. –
У меня была аналогичная проблема для вас и таким образом она была решена. использовать iOS 8 sdk, тогда viewWillLayoutSubviews ведет себя по-другому, поэтому кажется, что мы должны проверить версию системы, а в iOS8 использовать UIPresentationController. –
Я использовал первый подход, используя свойство preferedContectSize, которое работает как ожидается – Prasad