每当我旋转设备时,我的自定义键盘高度始终保持不变。我尝试删除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];
}
}
但是,当我加载自定义键盘设置第一次设置帧显示与横向以及纵向。
肖像:
景观:
我打电话说改变大小方法时,我的方向变化代表:
-(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和负载笔尖与参数设备方向的键盘布局,所有工作正常,但在设备方向尺寸的该更新是不会工作的。请在此帮助我
由于您正在编写iOS 8扩展,您应该采用iOS 8方法。而不是使用'willRotateToInterfaceOrientation:'你应该实现'viewWillTransitionToSize:'并且实现尺寸类而不是硬编码尺寸 – Paulw11 2014-10-09 09:52:11
那么定向和加载笔尖工作文件问题的方向没有问题,那就是我已经在实施改变尺寸了大小班。 – 2014-10-09 09:53:16
我不认为你的方法去除高度限制是正确的,因为你需要删除实际的约束对象实例,而不仅仅是一个等价的约束 - 你正在删除一个约束,它不存在于视图中,所以它没有影响。您应该尝试创建相对于包含视图边缘的约束,而不是指定高度 – Paulw11 2014-10-09 09:58:10