gpt4 book ai didi

ios - NumberKeyPad 中的完成按钮导致 iOS 8 出现问题

转载 作者:行者123 更新时间:2023-11-29 12:25:21 26 4
gpt4 key购买 nike

用于在 Numberkeypad 中添加完成按钮的代码

- (void)keyboardWillShow:(NSNotification *)note {
// create custom button
doneButton = [[UIButton alloc]init];
doneButton.frame = CGRectMake(0, 163, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
[doneButton setTitle:@"Done" forState:UIControlStateNormal];
[doneButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

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

if (IS_iOS_7_OR_LATER) {
dispatch_async(dispatch_get_main_queue(), ^{
UIView *keyboardView = [[[[[UIApplication sharedApplication] windows] lastObject] subviews] firstObject];
[doneButton setFrame:CGRectMake(0, keyboardView.frame.size.height - 53, 106, 53)];
[keyboardView addSubview:doneButton];
[keyboardView bringSubviewToFront:doneButton];

[UIView animateWithDuration:[[note.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue]-.02
delay:.0
options:[[note.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue]
animations:^{
self.view.frame = CGRectOffset(self.view.frame, 0, 0);
} completion:nil];
});
}else {
// locate keyboard view
dispatch_async(dispatch_get_main_queue(), ^{
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++) {
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard view found; add the custom button to it
if([[keyboard description] hasPrefix:@"UIKeyboard"] == YES)
[keyboard addSubview:doneButton];
}
});
}
}

我已经编写代码在数字键盘中添加完成按钮它与设备的默认键盘完美配合如果设备安装了第三方键盘 [swift keys App] 就会出现问题是否有办法识别第三方键盘以解决这个问题

提前致谢!

Device Default Keyboard Device Installed With Custom Keyboard

最佳答案

如果你愿意,我知道一种方法,但完全不是你说的;此方法不需要任何第三方库您只需创建 UIBarButton 并将按钮添加到 UIToolbar,最后只需在实现后添加您创建的工具栏

YourNumberTextField.inputAccessoryView = textFieldToolBar;

这是代码

UIToolbar* textFieldToolBar = [[UIToolbar alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
textFieldToolBar.barStyle = UIBarStyleBlackTranslucent;
textFieldToolBar.items = [NSArray arrayWithObjects:
[[UIBarButtonItem alloc]initWithTitle:@"Clear All" style:UIBarButtonItemStyleBordered target:self action:@selector("YourClearButtonFunctionName")],
[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil],
[[UIBarButtonItem alloc]initWithTitle:@"Ok!" style:UIBarButtonItemStyleDone target:self action:@selector("YourOkButtonFunctionName")],
nil];
[textFieldToolBar sizeToFit];
YourNumberTextField.inputAccessoryView = textFieldToolBar;

关于ios - NumberKeyPad 中的完成按钮导致 iOS 8 出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29282091/

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