无论我读了多少,我都坚持使用iOS中的一个概念,我似乎无法理解.我试图用自定义设计覆盖标准iOS数字键盘.当用户触摸UITextField时,我希望显示自定义inputView而不是标准数字键盘.
我为我的自定义inputView创建了一个单独的.h/.m/.xib ViewController类,名为"customInputViewController"现在,它只是一个黑暗的背景和一个按钮,当触摸UITextField时,它会遮挡大约一半的屏幕(类似于数字垫,但它看起来不同).当我单击自定义inputView中的一个按钮时,我的实现失败 - iOS会抛出EXC_BAD_ACCESS错误.
这是我在运行时加载.xib文件并将自定义inputView附加到UITextField对象的方法:
UIViewController *v = [[customInputViewController alloc] initWithNibName:@"customInputDesign" bundle:nil];
myTextInput.inputView = v.view;
Run Code Online (Sandbox Code Playgroud)
在自定义inputView的.xib文件中,我将File的Owner设置为"customInputViewController",然后创建了一个(IBAction)方法并将其附加到UIButton.单击该按钮时,(IBAction)设置为发送NSLog(@"按钮单击")消息.没什么特别的.它只是一个简单的样板实现,继续引发错误.
也许我这样做完全错了.有谁可以提供一个简单的例子?
我需要自定义大小UITextField's inputView.分配给我的自定义视图inputView已经是大小260x220但仍inputView显示为260x768(Portrait)和260x1024(Landscap).我试过改变inputView's Frame但仍然没有改变.无论如何我可以修改UITextField's inputView Frame它只占据底部屏幕的某些空间吗?
textField.inputView = numPadViewController.view;
[textField.inputView setFrame:CGRectMake(0, 0, 260, 220)];
Run Code Online (Sandbox Code Playgroud)
[编辑]
从这个,我也试过跟随,但没有工作!
numPadViewController.view.autoresizingMask = UIViewAutoresizingNone;
textField.inputView = numPadViewController.view;
Run Code Online (Sandbox Code Playgroud) 我有一个UITextField我设置inputView为自定义视图的位置.它的标准高度为216.我想将其设置为300或者屏幕的一半.
使用约束不是一种选择,因为它与默认值216冲突并且它会丢弃我的约束.
设置框架也不起作用.
有没有办法将其设置为更高的值?
在我的应用程序中,我使用的是自定义键盘.不是那种需要用户安装键盘然后能够在任何地方使用它的应用程序扩展 - 只需在我的应用程序中.
为此,我创建了一个子类,UIInputViewController并在自定义nib文件中设置我的键盘.然后,在文本字段上我需要显示这个键盘,它调用的是inputView UIInputViewController.
这是调用键盘的代码:
let myKeyBoard = MyKeyboard()
scoreField.inputView = myKeyBoard.inputView!
scoreField.becomeFirstResponder()
Run Code Online (Sandbox Code Playgroud)
然后,在UIInputViewController中,调用此代码:
class MyKeyboard: UIInputViewController {
var myKeyBoardView: UIInputView!
override func viewDidLoad() {
super.viewDidLoad()
self.loadInterface()
}
func loadInterface() {
//load nib and set in view
let nib = UINib(nibName: "MyKeyboard", bundle: nil)
myKeyBoardView = nib.instantiateWithOwner(self, options: nil)[0] as! UIInputView
self.inputView = myKeyBoardView
view.backgroundColor = myKeyBoardView.backgroundColor
}
Run Code Online (Sandbox Code Playgroud)
这让您了解我的代码到目前为止的样子.我现在要做的是将此键盘的高度设置为自定义值,比如说200.我已经扫描了谷歌和SO,我找到的所有解决方案都只是iOS 8,或者表示不使用nib文件.我认为了解如何在iOS 9和带有笔尖的情况下获得一些知识会很有用.
如何使用nib更改iOS 9中自定义UIInputViewController的高度?
我有UIView一个签名。签名是通过签名视图上的自定义 inputView 输入的。在绘制签名视图时,我利用它是第一响应者这一事实来突出显示正在编辑的视图,并且我还覆盖了该resignFirstResponder方法以计算何时停止将其显示为正在编辑。
所以代码看起来像这样:
@implementation SignatureView
-(BOOL) becomeFirstResponder {
BOOL result = [super becomeFirstResponder];
[self showEditingMode];
return result;
}
-(BOOL) resignFirstResponder {
BOOL result = [super resignFirstResponder];
[self showViewingMode];
return result;
}
-(UIView *) inputView {
if (!keyboard)
keyboard = [[SignatureKeyboardView alloc] initWithStuff:stuff....];
return keyboard;
}
@end
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,在 iOS 11 上,resignFirstResponder不再调用该方法。在以前版本的 iOS 上,它曾经被调用,然后我可以更改 UI 以显示它不再被编辑。
这仅在UIScrollView设置为拖动时关闭键盘时发生,并且用户拖动UIScrollView. 如果用户改为点击UIView可以成为第一响应者的另一个,例如 a UITextField,resignFirstResponder则被调用。
我是否遗漏了 iOS11 中更改的某些内容或遇到了错误?
我使用textFields inputView属性来显示UIPickerViews而不是键盘.我编程的方式,我没有在.H文件中声明PickerViews,或者在界面构建器的视图中连接它们.当我实现pickerviews的属性时,我无法使每个属性具有不同的属性.我尝试使用"if"语句告诉它具有不同的属性,具体取决于使用的选择器如下....
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)agePickerView {
if ([pickerView isEqual: agePickerView]){
return 1;
}
if ([pickerView isEqual: weightPickerView]){
return 1;
}
Run Code Online (Sandbox Code Playgroud)
}
当我这样做时,它会说weightPickerView是未声明的.所以这是我实现pickerViews的代码.
@implementation MainViewController
//WEIGHT FIELD CODE
-(IBAction)weightFieldDidBeginEditing{
UIPickerView *weightPickerView = [[UIPickerView alloc] init];
weightField.inputView = weightPickerView;
weightPickerView.showsSelectionIndicator = YES;
weightPickerView.delegate = self;
weightPickerView.dataSource = self;
[weightPickerView release];
UIToolbar *weightToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,320,44)];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(pickerDoneClicked:)];
[weightToolBar setItems:[NSArray arrayWithObject:doneButton] animated:NO];
weightField.inputAccessoryView = weightToolBar;
}
-(NSInteger)weightpickerView:(UIPickerView *)weightPickerView numberOfRowsInComponent: (NSInteger)component{
return [weightPickerArray count];
}
-(NSString *)weightpickerView:(UIPickerView*)weightPickerView titleForRow:(NSInteger)row …Run Code Online (Sandbox Code Playgroud) 我需要在UISearchBar中设置我的自定义inputView.
所以我写了以下代码,这在iOS5和iOS6中完美运行.
但它在iOS7中不起作用.
for(int i =0; i<[self.searchBar.subviews count]; i++) {
if([[self.searchBar.subviews objectAtIndex:i] isKindOfClass:[UITextField class]])
{
[(UITextField*)[searchBar.subviews objectAtIndex:i] setFont:[UIFont fontWithName:@"MyCustomFont" size:15]];
UITextField* search=(UITextField*)[searchBar.subviews objectAtIndex:i];
search.delegate = self;
[(UITextField*)[self.searchBar.subviews objectAtIndex:i] setInputView:self.customKeyboard];
[self.customKeyboard setTextView:search];
}
}
[self.sBar reloadInputViews];
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
在我的viewDidLoad我有以下代码:
UIDatePicker* datePicker = [[UIDatePicker alloc] init];
datePicker.datePickerMode = UIDatePickerModeDate;
[datePicker addTarget:self action:@selector(datePickerChanged:) forControlEvents:UIControlEventValueChanged];
dateField1.inputView = datePicker;
dateField2.inputView = datePicker;
dateField3.inputView = datePicker;
dateField4.inputView = datePicker;
Run Code Online (Sandbox Code Playgroud)
(dateField都是UITextFields)
在我的-(void)datePickerChanged:(UIDatePicker*)datePicker
方法中,我如何知道正在编辑哪个dateField,以便我可以填写选择的日期?
目前我正在为每个UITextField使用一个新的UIDatePicker,但我希望这种情况有一个更优雅的解决方案.
任何帮助表示赞赏!
我试图让我的 Inputview 的背景透明,但我只把它变成灰色。
代码是:
let fakeField : UITextField = UITextField(frame: CGRect.zero)
//1
InputViewCollection = InputView(frame: CGRect(x: 0, y: 0, width: 0, height: 216)) //Intialize custom input view
InputViewCollection?.delegate = self //delegate
InputViewCollection?.dataSource = self //datasource
//2
InputViewCollection?.backgroundColor = UIColor.clear
self.fakeField.inputView = InputViewCollection //Assign input view
self.fakeField.keyboardAppearance = .default
self.view.addSubview(self.fakeField)
Run Code Online (Sandbox Code Playgroud)
如何离开输入视图的透明背景?
谢谢
我开发了一个带视图和视图控制器的自定义键盘.在我的应用程序的主视图控制器中,我持有自定义键盘视图控制器的属性.
我有一个textView应该从自定义键盘输入.该customKeyboard属性是自定义键盘的视图控制器.
我viewDidLoad在主应用程序中添加了以下内容viewController.
self.textView.inputView = self.customKeyboard.view;
Run Code Online (Sandbox Code Playgroud)
当我做第textView一个响应者时,会出现标准系统键盘.IB似乎将我的textView属性链接到UI组件.要使自定义键盘出现,我需要做什么?
我编写了一个自定义输入视图,用于替换标准键盘UITextView.如果我给你我的自定义UIView为我UITextView的inputView,它按预期工作在纵向和横向模式.
当我旋转设备时会出现问题 - 每当我这样做时,我的自定义UIView会扩展以填满整个屏幕,而不是仅仅覆盖键盘.我没有任何自定义调整大小代码 - 我只是将UIView指定为UITextView的inputView属性,然后旋转设备.
如何在旋转设备时将自定义键盘视图仅占用普通键盘占用的空间?
inputview ×11
ios ×9
uitextfield ×4
keyboard ×2
swift ×2
uitextview ×2
ios7 ×1
ipad ×1
iphone ×1
nib ×1
objective-c ×1
textfield ×1
uidatepicker ×1
uipickerview ×1
uiscrollview ×1
uisearchbar ×1
xcode ×1