iOS自定义键盘增加UIInputViewController高度
我只是无法理解文档中关于让iOS定制键盘的高度正常工作的说法 这是一个干净的键盘目标,添加了似乎是apple docs的内容和许多正确答案,但在XS和6S模拟器上不起作用:iOS自定义键盘增加UIInputViewController高度,ios,objective-c,custom-keyboard,Ios,Objective C,Custom Keyboard,我只是无法理解文档中关于让iOS定制键盘的高度正常工作的说法 这是一个干净的键盘目标,添加了似乎是apple docs的内容和许多正确答案,但在XS和6S模拟器上不起作用: // //KeyboardViewController.m //键盘 // //由hiwa于2019年4月2日创建。 //版权所有©2019 hiwa。版权所有。 // #导入“KeyboardViewController.h” @接口KeyboardViewController() @属性(非原子,强)UIButton*n
//
//KeyboardViewController.m
//键盘
//
//由hiwa于2019年4月2日创建。
//版权所有©2019 hiwa。版权所有。
//
#导入“KeyboardViewController.h”
@接口KeyboardViewController()
@属性(非原子,强)UIButton*nextKeyboardButton;
@结束
@键盘视图控制器的实现
-(无效)updateViewConstraints{
[super updateViewConstraints];
//在此处添加自定义视图大小限制
}
-(无效)视图显示:(BOOL)动画{
[超级视图显示:动画];
NSLayoutConstraint*高度约束=
[NSLayoutConstraint约束项:self.view
属性:NSLayoutAttributeHeight
关系人:NSLayoutRelationEqual
toItem:无
属性:nsLayoutAttribute属性
乘数:0.0
常数:300];
[self.view addConstraint:heightConstraint];
}
-(无效)viewDidLoad{
[超级视图下载];
//在此处执行自定义UI设置
self.nextKeyboardButton=[UIButton Button类型:UIButtonTypeSystem];
[self.nextKeyboardButton设置标题:NSLocalizedString(@“下一个键盘”,“下一个键盘”按钮的标题)用于状态:UIControlStateNormal];
[self.nextKeyboardButton sizeToFit];
[self.nextKeyboardButton addTarget:self action:@selector(handleInputModeListFromView:withEvent:)for controlEvents:UIControlEventAllTouchEvents];
[self.view addSubview:self.nextKeyboardButton];
}
-(无效)textWillChange:(id)textInput{
//应用程序即将更改文档的内容。请在此执行任何准备工作。
}
-(无效)textDidChange:(id)textInput{
//应用程序刚刚更改了文档的内容,文档上下文已更新。
UIColor*textColor=nil;
if(self.textDocumentProxy.keyboardAppearance==UIKeyboardAppearanceDark){
textColor=[UIColor-whiteColor];
}否则{
textColor=[UIColor blackColor];
}
[self.nextKeyboard按钮设置标题颜色:文本颜色用于状态:uicontrol状态正常];
}
@结束
感谢您在此提供的任何提示。基于开发人员代码级别票据:
keysView
)keysView
添加到UIInputViewController的视图中keysView.frame
与self.view
keysView
keysView
,它与self.view
一样高
完整代码:
#导入“KeyboardViewController.h”
@接口KeyboardViewController()
@属性(非原子,强)UIButton*nextKeyboardButton;
@结束
@键盘视图控制器的实现
-(无效)viewDidLoad{
[超级视图下载];
// (1)
UIView*KeyView=[[UIView alloc]initWithFrame:CGRectMake(0,0,100,100)];
// (3)
NSLayoutConstraint*键盘高度约束=[NSLayoutConstraint]
constraintWithItem:self.view
属性:NSLayoutAttributeHeight
关系人:NSLayoutRelationEqual
toItem:无
属性:nsLayoutAttribute属性
乘数:0.0
常数:310];
[键盘高度约束设置优先级:UILayoutPriorityDefaultHigh];
[self.view addConstraints:@[keyboardHeightConstraint];
self.nextKeyboardButton=[UIButton Button类型:UIButtonTypeSystem];
[self.nextKeyboardButton设置标题:NSLocalizedString(@“下一个键盘”,“下一个键盘”按钮的标题)用于状态:UIControlStateNormal];
[self.nextKeyboardButton sizeToFit];
self.nextKeyboardButton.translates自动调整大小GMaskintoConstraints=否;
[self.nextKeyboardButton addTarget:self action:@selector(advanceToNextInputMode)for controlEvents:UIControlEventTouchUpInside];
[keysView addSubview:self.nextKeyboardButton];
// (5)
NSLayoutConstraint*nextKeyboardButtonLeftSideConstraint=[NSLayoutConstraint constraintWithItem:self.nextKeyboardButton属性:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual-toItem:KeyView属性:NSLayoutAttributeLeft乘数:1.0常量:0.0];
NSLayoutConstraint*nextKeyboardButtonBottomConstraint=[NSLayoutConstraint constraintWithItem:self.nextKeyboardButton属性:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual-toItem:KeyView属性:NSLayoutAttributeBottom乘数:1.0常量:0.0];
[KeyView addConstraints:@[nextKeyboardButtonLeftSideConstraint,nextKeyboardButtonBottomConstraint]];
// (4)
keysView.frame=CGRectMake(0,0,self.view.bounds.size.width,self.view.bounds.size.height);
// (2)
[self.view addSubview:keysView];
}
-(无效)解除锁定{
self.nextKeyboardButton=nil;
}
@结束
基于开发人员代码级别票据:
keysView
)keysView
添加到UIInputViewController的视图中keysView.frame
与self.view
keysView
keysView
,它与self.view
一样高。