我只是不明白文档中关于让我的iOS自定义键盘工作的高度是怎么说的。
这是干净的键盘目标,并添加了什么似乎是苹果文档和许多SO答案作为正确答案,但它不工作在XS和6S模拟器:
//
// KeyboardViewController.m
// keyboard
//
// Created by hiwa on 02/04/2019.
// Copyright © 2019 hiwa. All rights reserved.
//
#import "KeyboardViewController.h"
@interface KeyboardViewController ()
@property (nonatomic, strong) UIButton *nextKeyboardButton;
@end
@implementation KeyboardViewController
- (void)updateViewConstraints {
[super updateViewConstraints];
// Add custom view sizing constraints here
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSLayoutConstraint *heightConstraint =
[NSLayoutConstraint constraintWithItem: self.view
attribute: NSLayoutAttributeHeight
relatedBy: NSLayoutRelationEqual
toItem: nil
attribute: NSLayoutAttributeNotAnAttribute
multiplier: 0.0
constant: 300];
[self.view addConstraint: heightConstraint];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Perform custom UI setup here
self.nextKeyboardButton = [UIButton buttonWithType:UIButtonTypeSystem];
[self.nextKeyboardButton setTitle:NSLocalizedString(@"Next Keyboard", @"Title for 'Next Keyboard' button") forState:UIControlStateNormal];
[self.nextKeyboardButton sizeToFit];
[self.nextKeyboardButton addTarget:self action:@selector(handleInputModeListFromView:withEvent:) forControlEvents:UIControlEventAllTouchEvents];
[self.view addSubview:self.nextKeyboardButton];
}
- (void)textWillChange:(id<UITextInput>)textInput {
// The app is about to change the document's contents. Perform any preparation here.
}
- (void)textDidChange:(id<UITextInput>)textInput {
// The app has just changed the document's contents, the document context has been updated.
UIColor *textColor = nil;
if (self.textDocumentProxy.keyboardAppearance == UIKeyboardAppearanceDark) {
textColor = [UIColor whiteColor];
} else {
textColor = [UIColor blackColor];
}
[self.nextKeyboardButton setTitleColor:textColor forState:UIControlStateNormal];
}
@end
感谢你的提示。
2条答案
按热度按时间dkqlctbz1#
基于开发人员代码级别票证:
1.将按钮添加到UIView(例如
keysView
)1.将
keysView
添加到UIInputViewController的视图中。1.添加问题中的约束
1.使
keysView.frame
与self.view
相同1.将至少一个常量添加到
keysView
的其中一个按钮现在,您应该有一个扩展的
keysView
,它与self.view
一样高。完整代码:
js81xvg62#
对于Swift:覆盖视图高度约束的UIInputViewController的viewWillAppear方法。类似于以下内容。