1

설치 : 'VC1'은 루트보기 컨트롤러 'VC2'로 'NavigationVC'를 만들고 프리젠 테이션 스타일 UIModalPresentationFormSheet로 모달로 표시합니다. 'VC2'는 올바른 크기의 화면 중간에 탐색 컨트롤러 내부에 나타납니다.새로운보기 컨트롤러를 누를 때마다 크기 조정 탐색 컨트롤러가 모달로 표시됩니다.

문제 : View Controller를 모달 NavVC로 계속 밀어 넣으면서 크기를 조정하고 싶습니다. 푸시 된 각 뷰 컨트롤러에서 내 preferredContentSize의 NSLog는 내 제약 조건이 정확하고 크기가 실제로 다른지 확인합니다. 그러나 나는 광범위하게 실험했으며 모달의 크기를 바꾸는 방법을 찾지 못했습니다.

@implementation VC1() 

- (void) viewDidLoad{ 
    VC1* vc1 = [self getNextVC]; 
    NavVC* navVC = [[UINavigationViewController alloc] initWithRootViewController:vc1]; 
    [navVC setModalPresentationStyle:UIModalPresentationFormSheet]; 
    [self presentViewController:navVC animated:YES completion:nil]; 
} 

@end 

@implementation NavVC() 

- (CGSize) preferredContentSize{ 
    CGSize size = [[self topViewController] preferredContentSize]; 
    return size; 
} 

@end 


@implementation VC2() 

- (CGSize) preferredContentSize{ 
    CGSize size = [[self view] systemLayoutSizeFittingSize:UILayoutFittingCompressedSize]; 
    return size; 
} 

@end 

답변

4

나는 같은 문제를 다루는 데 시간을 할애했다. iOS8 용 모달 탐색 컨트롤러에서보기 컨트롤러를 누르면 루트 컨트롤러와 크기가 같은보기 컨트롤러가 생성되었지만 iOS7의 경우이 두 번째보기 컨트롤러는 모달 폼 시트 (540.f, 620.f)의 기본 크기를 가졌습니다. . 유일한 작업 솔루션, 나는 두 iOS7에 대한 지금까지 가지고 올 수 있고 iOS8의는 다음과 같다 : ViewController1을 제시

ViewController1.m

@interface ViewController1() 

@end 

@implementation ViewController1 

-(void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
    self.navigationController.view.superview.bounds = CGRectMake(0, 0, VC1_WIDTH, VC1_HEIGHT); 
} 

- (void)nextTapped:(id)sender { 
    ViewController2 *vc2 = [storyboard instantiateViewControllerWithIdentifier:@"ViewController2"]; 
    [self.navigationController pushViewController:vc2 animated:NO]; 
    // call after push 
    self.navigationController.view.superview.bounds = CGRectMake(0, 0,VC2_WIDTH,VC2_HEIGHT); 
} 

@end 

:

ViewController1 *vc1 = [storyboard instantiateViewControllerWithIdentifier:@"ViewController1"]; 
    UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:vc1]; 
    navVC.modalPresentationStyle = UIModalPresentationFormSheet; 
    [self presentViewController:navVC animated:NO completion:nil]; 

ViewController2.m

#import "ViewController2.h” 

@interface ViewController2() 

@end 

@implementation ViewController2 

-(void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
    self.navigationController.view.superview.bounds = CGRectMake(0, 0, VC2_WIDTH, VC2_HEIGHT); 
} 

- (void)nextTapped:(id)sender { 
    ViewController3 *vc3 = [storyboard instantiateViewControllerWithIdentifier:@"ViewController3”]; 
    [self.navigationController pushViewController:vc3 animated:NO]; 
    self.navigationController.view.superview.bounds = CGRectMake(0, 0,VC3_WIDTH,VC3_HEIGHT); 
} 

- (void)backTapped:(id)sender { 
    self.navigationController.view.superview.bounds = CGRectMake(0, 0,VC1_WIDTH,VC1_HEIGHT); 
    [self.navigationController popViewControllerAnimated:NO]; 
} 

@end 

ViewController3.m

#import "ViewController3.h” 

@interface ViewController3() 

@end 

@implementation ViewController3 

-(void)viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
    self.navigationController.view.superview.bounds = CGRectMake(0, 0, VC3_WIDTH, VC3_HEIGHT); 
} 

- (void)backTapped:(id)sender { 
    self.navigationController.view.superview.bounds = CGRectMake(0, 0,VC2_WIDTH,VC2_HEIGHT); 
    [self.navigationController popViewControllerAnimated:NO]; 
} 

@end 

모달 탐색 컨트롤러에 푸시 된보기 컨트롤러에 텍스트 입력 필드를 추가하는 경우 iOS8의 경우 키보드 표시 및 해제가 자동으로 잘못된 크기로 조정됩니다. 불행히도이 문제에 대한 적절한 수정이 아직 없습니다.

+0

navigationController? .preferredContentSize = CGSize (width : preferredContentSize.width, height : preferredContentSize.height)를 viewWillAppear에서 설정하여 텍스트 필드 문제를 수정할 수 있습니다. –