2

デバイスを回転させても、カスタム キーボードの高さは常に同じままです。削除Constraintsして再度追加しようとしましたが、うまくいきません。Stack Overflow と iOS dev Forum で関連する質問をたくさん見ましたが、まだ解決策がありません..

アプリを使用した場所をいくつか読みまし-(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];
    }

}

しかし、初めて設定するカスタムキーボードをロードするときはいつでも、横向きと縦向きのセッターフレーム表示を設定します。

肖像画:

ここに画像の説明を入力

風景:

ここに画像の説明を入力

オリエンテーション変更デリゲート時にサイズ変更メソッドを呼び出します。

-(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を使用しており、デバイスの向きとしてペン先を読み込んでいますが、デバイスの向きでのサイズの更新はうまくいきません。これについて私を助けてください

4

2 に答える 2

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];
}
于 2014-10-09T10:08:59.330 に答える