gpt4 book ai didi

iphone - 删除 iPhone 普通键盘中的完成按钮

转载 作者:行者123 更新时间:2023-12-03 20:53:05 28 4
gpt4 key购买 nike

我有两个编辑文本,一个编辑文本输入应该只接受数字,以便我显示数字键盘。数字键盘上没有完成按钮。所以现在我添加完成按钮 using this link现在“完成”按钮工作正常。我的问题是我的另一个编辑文本是普通键盘,键盘也将显示“完成”按钮。我想避免在该特定编辑文本中使用“完成”按钮。 enter image description here请指导我如何删除普通键盘中的该按钮..

最佳答案

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2)
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidShow:)
name:UIKeyboardDidShowNotification
object:nil];
}
else
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
}

- (void)addButtonToKeyboard
{
// create custom button

doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame = CGRectMake(0, 163, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.0)
{
[doneButton setImage:[UIImage imageNamed:@"Btn-DoneDown-2.png"] forState:UIControlStateNormal];
[doneButton setImage:[UIImage imageNamed:@"Btn-DoneUp-2.png"] forState:UIControlStateHighlighted];
}
else
{
[doneButton setImage:[UIImage imageNamed:@"Btn-DoneDown-1.png"] forState:UIControlStateNormal];
[doneButton setImage:[UIImage imageNamed:@"Btn-DoneUp-1.png"] forState:UIControlStateHighlighted];
}

[doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];

// locate keyboard view

UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;

for(int i = 0 ; i < [tempWindow.subviews count] ; i++)
{
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard found, add the button
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2)
{
if([[keyboard description] hasPrefix:@"<UIPeripheralHost"] == YES)
[keyboard addSubview:doneButton];
}
else
{
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
[keyboard addSubview:doneButton];
}
}
}

- (void)keyboardWillShow:(NSNotification *)note
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 3.2)
{
[self addButtonToKeyboard];
}
}

- (void)keyboardDidShow:(NSNotification *)note
{
if(doneButton)
{
[doneButton removeFromSuperview];
doneButton = nil;
}
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 3.2)
{
[self addButtonToKeyboard];
}
}

- (void)doneButton:(id)sender
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[doneButton removeFromSuperview];
doneButton = nil;
}

关于iphone - 删除 iPhone 普通键盘中的完成按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8710731/

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