0

장치를 회전시킬 때마다 사용자 정의 키보드 높이는 항상 동일하게 유지됩니다. 나는 Constraints을 제거하고 다시 운을 추가하려고합니다. 스택 오버플로 및 iOS 개발자 포럼에서 많은 관련 질문을 보았습니다.하지만 여전히 해결책이 없습니다.장치 방향이 바뀔 때 사용자 정의 키보드 높이가 변경되지 않습니다.

일부는 애플 리케이션 -(void)viewDidAppear:(BOOL)animated으로 읽었지 만 일단이 코드를 사용하여 크기를 설정하면 :

-(void)viewDidAppear:(BOOL)animated { 

    [super viewDidAppear:animated]; 
    [self updateCustomHeight]; 
} 


-(void)updateCustomHeight 
{ 

    [self updateViewConstraints]; 
    CGFloat _expandedHeight = 250; 

    NSLayoutConstraint *_heightConstraint = [NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0 constant:_expandedHeight]; 

    [self.view removeConstraint: _heightConstraint]; 
    [self.view layoutIfNeeded]; 

    if(isPortrait) 
    { 



     CGFloat _expandedHeight = 230; 

     NSLayoutConstraint *_heightConstraint = [NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0 constant: _expandedHeight]; 

     [self.view addConstraint: _heightConstraint]; 

    } 
    else 
    { 

     CGFloat _expandedHeight = 200; 

     NSLayoutConstraint *_heightConstraint = [NSLayoutConstraint constraintWithItem:self.view attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0 constant: _expandedHeight]; 

     [self.view addConstraint: _heightConstraint]; 
    } 

} 

그러나 내가 언제 처음 세로 프레임뿐만 아니라 세로 방향으로 세터 프레임 표시를 설정하는 사용자 지정 키보드를로드합니다.

세로 :

enter image description here

풍경 :

enter image description here

내가 그 변화의 크기 메서드를 호출 할 때 내 방향 변경 위임 :

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    if([UIScreen mainScreen].bounds.size.width < [UIScreen mainScreen].bounds.size.height){ 
     //Keyboard is in Portrait 
     isPortrait=YES; 

     [self LoadKeyboardview]; 
     [self updateCustomHeight]; 

    } 
    else{ 

     isPortrait=NO; 

     [self LoadKeyboardview]; 
     [self updateCustomHeight]; 

     //Keyboard is in Landscape 
    } 


} 

참고 : 내가 XIB 및로드 펜촉으로 파 장치 방향을 사용하고있는 키보드 레이아웃에 대한

모든 작업 잘하지만 실 거예요 작업 장치 방향의 크기의 갱신. 이 날 도와주세요

+0

iOS 8 확장을 작성하고 있으므로 iOS 8 방법을 채택해야합니다. 'willRotateToInterfaceOrientation :'을 사용하는 대신'viewWillTransitionToSize :'를 구현하고 하드 코딩 된 치수가 아닌 크기 클래스를 구현해야합니다. – Paulw11

+0

오리 엔테이션과로드 닙의 작업 파일 이슈가 변경 크기가 작동하지 않습니다. 크기 클래스. –

+0

등가 제약 조건뿐만 아니라 실제 제약 조건 인스턴스를 제거해야하므로 높이 제약 조건을 제거하는 방법이 올바르지 않다고 생각합니다.보기에 존재하지 않는 제약 조건을 제거하고 있으므로 제약 조건이 없습니다. 효과. 당신은 높이를 지정하는 것보다보기의 가장자리를 포함하여 상대적으로 제약 조건을 만들어야 만합니다. – Paulw11

답변

1

높이 제약 조건을 추가 할 때 이후에 제거 할 수 있도록 속성에 유지해야합니다.

@property (strong,nonatomic) NSLayoutConstraint *heightConstraint; 

-(void)updateCustomHeight 
{ 

    [self updateViewConstraints]; 
    CGFloat expandedHeight = 250; 

    if (self.heightConstraint != nil) { 
     [self.view removeConstraint:self.heightConstraint]; 
     [self.view layoutIfNeeded]; 

    if(isPortrait) 
    { 
     expandedHeight = 230; 
    } 
    else 
    { 

     expandedHeight = 200; 
    } 

    self.heightConstraint = [NSLayoutConstraint constraintWithItem:self.view  attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:0.0 constant: expandedHeight]; 
    [self.view addConstraint:self.heightConstraint]; 
    [self.view layoutIfNeeded]; 
} 
+0

답변을 주셔서 감사하지만 같은 출력을 얻지 못합니다. @ paulw11 :( –

+0

예를 들어'updateViewConstraints'는 무엇을할까요? 적절한 제약 조건을 가진 하나의 스토리 보드를 사용해야합니다. 크기 클래스 - 코드에서 아무 것도 할 필요가 없습니다. – Paulw11

0

시도 내가 문제를 해결할 수 있었다 풍경

- (void)updateViewConstraints { 
    [super updateViewConstraints]; 

    if([UIScreen mainScreen].bounds.size.width < [UIScreen mainScreen].bounds.size.height) 
    { 

     [self.view removeConstraint:_heightConstraintforLandscape]; 

    } 
    else 
    { 
     [self.view removeConstraint:_heightConstraintforPortrait]; 
    } 
} 

두 제약 초상화 하나 하나를 추가. 문제는 우선 순위 때문입니다. 다른 우선 순위를 설정한다고해도 이니셜을 고려해야 할 이유가 무엇인지 알지 못합니다.

어쨌든 가로 및 세로에 서로 다른 제약 조건을 설정하면 맞춤 높이를 유지하는 데 도움이되었습니다. 누군가가 도움이되기를 바랍니다.

관련 문제