gpt4 book ai didi

ios - 当 View 已向上移动键盘时,UINavigationBar BarButtonItems 不响应点击

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

我在显示键盘时将模态视图向上移动,以防止界面的某些部分被键盘隐藏。

当 View 已移动时,工具栏取消/保存按钮不会响应点击。检测到模态内的点击并响应良好。

enter image description here

我已经将其设置为当在文本字段外点击时键盘应该消失,但是当点击导航栏时这也不起作用。

当 View 被偏移时,我如何适本地响应对 barbuttonitems 的点击?

这是我在显示键盘时向上移动模式的方法:

- (void) animateTextField: (UITextField*) textField up: (BOOL) up
{
int movementDistance;
float movementDuration;

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {

if(
UIInterfaceOrientationIsLandscape(self.interfaceOrientation)
)
{
//code for landscape shift - not relevant because you can't see the toolbar
else{
NSLog(@"Portrait for animation");
movementDistance = IPAD_PORTRAIT_KEYBOARD_HEIGHT;
movementDuration = KEYBOARD_ANIMATION_DURATION;

if(up){
keyboardAppearedInLandscape = false;
}else{
//the keyboard is going down
NSLog(@"Keyboard going down");
//is the iPad in the same orientation now that it was when it came up?
if ([[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIInterfaceOrientationPortraitUpsideDown)
{
if (!keyboardAppearedInLandscape) {
//don't do anything - the keyboard is being dismissed in the same way it was called. It's much the same in any case.
}else{
movementDistance = IPAD_LANDSCAPE_KEYBOARD_HEIGHT;
}
}
}
}

}
int movement = (up ? -movementDistance : movementDistance);

[UIView beginAnimations: @"anim" context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: movementDuration];
self.view.frame = CGRectOffset(self.view.frame, 0, movement);
[UIView commitAnimations];
}
//end text field movy-ness

下面是我如何检测文本字段外的点击以关闭键盘:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
//keyboard goes away if you tap somewhere else on screen
NSLog(@"resignFirstResponder");
[self.view endEditing:YES];

}

[super touchesBegan:touches withEvent:event];

}

最佳答案

您不会收到原始矩形边界之外的触摸事件,因为...

  • SuperView 认为 View 没有改变位置
  • View 在自身内部向上移动,而不是从外部移动
  • 屏幕上的视觉元素正在变化但未被识别

相反,正确移动 subview :

  1. SuperView 应该响应 UIKeyboard
    • 利用UIKeyboardWillHideNotification && UIKeyboardWillShowNotification
  2. ClipsToBounds 设置为 YES
    • 现在您将看不到 View 边界之外的内容。
    • 使调试更有效

查看:

关于ios - 当 View 已向上移动键盘时,UINavigationBar BarButtonItems 不响应点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12464969/

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