デバイスを回転させても、カスタム キーボードの高さは常に同じままです。削除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を使用しており、デバイスの向きとしてペン先を読み込んでいますが、デバイスの向きでのサイズの更新はうまくいきません。これについて私を助けてください