gpt4 book ai didi

iOS:在 iPad 模态视图中获取键盘点的顶部?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:36:18 25 4
gpt4 key购买 nike

我需要在显示键盘时调整“消息栏”,并且在使用 iPad 模态视图 Controller 时遇到问题。 “消息栏”在显示时应位于键盘的正上方,然后在键盘隐藏时位于模式的底部(消息应用程序样式)。

问题是我需要根据 Modal 的坐标系获取键盘框架的最高点。我发现这个答案在理论上似乎是正确的,但不起作用(How can I find portion of my view which isn't covered by the keyboard (UIModalPresenationStyleFormSheet)?):

仅供引用 当显示键盘时,主窗口中的键盘框架(即“keyboardFrame”)= (-84.0, 526.0, 768.0, 264.0)。为模态视图 Controller 坐标系(即“newSize”)转换时的键盘框架 = (-168.0, 292.0, 768.0, 264.0)*

// Convert the keyboard rect into the view controller's coordinate system
// The fromView: nil means keyboardRect is in the main window's coordinate system
let newSize = self.view.convertRect(keyboardFrame, fromView: nil)

// And then this is the part that gets covered!
let keyboardCoveredHeight = self.view.bounds.height - newSize.origin.y
self.messageToolbar.bottomConstraint.constant = -keyboardCoveredHeight

enter image description here

最佳答案

我最终使用熟悉的类别在 iPad 模态视图中获得正确的键盘框架:

- (CGFloat)heightCoveredByKeyboardOfSize:(CGSize)keyboardSize
{
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
CGRect frameInWindow = [self convertRect:self.bounds toView:nil];
CGRect windowBounds = self.window.bounds;

CGFloat keyboardTop;
CGFloat heightCoveredByKeyboard;

//Determine height of the view covered by the keyboard relative to current rotation

switch (orientation)
{
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
keyboardTop = windowBounds.size.height - keyboardSize.height;
heightCoveredByKeyboard = windowBounds.size.height - frameInWindow.origin.y - keyboardTop;
break;
case UIInterfaceOrientationPortraitUpsideDown:
default:
keyboardTop = windowBounds.size.height - keyboardSize.height;
heightCoveredByKeyboard = CGRectGetMaxY(frameInWindow) - keyboardTop;
break;
}

return MAX(0.0f,heightCoveredByKeyboard);
}

连同 DAKeyboardControl(用于平移):

    // Use [unowned self] in closure for weak reference
self.view.addKeyboardPanningWithFrameBasedActionHandler(nil, constraintBasedActionHandler: { [unowned self] (keyboardFrameInView, opening, closing) -> Void in
if opening
{
if UIDevice.isIpad()
{
// iPad requires a different method due to use of modal view
self.messageToolbar.bottomConstraint.constant = -self.view.heightCoveredByKeyboardOfSize(keyboardFrameInView.size)
}
else
{
self.messageToolbar.bottomConstraint.constant = -keyboardFrameInView.size.height
}
}

if closing
{
self.messageToolbar.bottomConstraint.constant = 0
}

self.view.updateConstraintsIfNeeded()
self.view.layoutIfNeeded()
})

关于iOS:在 iPad 模态视图中获取键盘点的顶部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30361527/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com