每当我旋转设备时,我的自定义键盘高度始终保持不变。我尝试删除Constraints
并再次添加它,但没有运气。我在 Stack Overflow 和 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];
}
}
但是,当我加载自定义键盘时,设置第一次设置器框架显示为横向和纵向。
肖像:
景观:
当我的方向更改委托时,我调用该更改大小方法:
-(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并将 nib 加载为 par 设备方向,一切正常,但设备方向的大小更新不起作用。请帮助我