swift - 自定义iOS键盘:如何根据不同的iPad调整键盘框架
问题描述
这是问题:
所以我在 iPad 上构建了一个自定义的 iOS 键盘,当然,我希望它可以在多个 iPad 上工作。我已经对其进行了设置,以便 UIView 在 XIB 中制作并在我的 InputViewController 中实例化。现在,它设置为我的 XIB 中指定的框架。我希望键盘位于屏幕的下三分之一处,覆盖屏幕的宽度,因此不会溢出。
我尝试在 InputViewController、awakeFromNib()、viewDidLayoutSubviews() 和 viewWillAppear() 中调整 viewDidLoad() 中的框架,但是当我尝试这些时,只出现黑屏。
这是我的代码(视图是bibleKeyboardView
)
class KeyboardViewController: UIInputViewController {
// A property to hold reference to a BibleKeyboardView object
var bibleKeyboardView: BibleKeyboardView!
override func viewDidLoad() {
super.viewDidLoad()
// An instance of BibleKeyboardView is added to the controller's root inputView
let nib = UINib(nibName: "BibleKeyboardView", bundle: nil)
let objects = nib.instantiate(withOwner: nil, options: nil)
bibleKeyboardView = (objects.first as! BibleKeyboardView)
guard let inputView = inputView else { return }
inputView.addSubview(bibleKeyboardView)
// controls visibility of the globe key
bibleKeyboardView.setNextKeyboardVisible(needsInputModeSwitchKey)
// adds automatic handle switching to glove key
bibleKeyboardView.nextKeyboardBtn.addTarget(self,
action:
#selector(handleInputModeList(from:with:)),
for: .allTouchEvents)
bibleKeyboardView.delegate = self
let screenBounds = UIScreen.main.bounds
let screenWidth = screenBounds.width
let screenHeight = screenBounds.height
// This is the part that was causing my blank screen
bibleKeyboardView.frame = CGRect(x: 0, y: screenHeight * 0.67, width: screenWidth, height: screenHeight * 0.33)
}
如果有帮助,这是我的键盘视图的图片
这是我尝试分配时的键盘图片bibleKeyboardView.frame
任何帮助将非常感激!在过去的几天里,这让我很难过。
解决方案
推荐阅读
- android - 我们如何在 Android Studio 中禁用离线模式?
- mysql - MySql Server 使用最新的 C++ Redistributable 2015-2019 安装问题
- r - 如何创建变量名称及其级别的表?
- visual-studio - CMake项目使用外部SDK工具链文件交叉编译错误
- r - R 在 do.call(rbind) 上设置列名
- c# - C# 我的应用程序在任务管理器中启动但未显示在桌面中
- javascript - ngDestroy 生命周期未在动态创建的 Angular 组件中触发
- swift - 你可以在没有 segue 的情况下更改视图控制器吗?
- ios - 如何在单个tableview中传递多个数据
- laravel - Laravel 在控制器中从另一个类重定向