J'ai un champ de texte, j'ai besoin d'afficher le curseur et de cacher le clavier. Il semble correct dans l'IOS 6 et l'IOS 5. Mais dans l'IOS 7, je peux voir une petite ligne blanche en bas.
Mon code est
UIScrollView *scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
[scrollview setDelegate:self];
[self.view addSubview:scrollview];
[self.view bringSubviewToFront:scrollview];
[scrollview setBackgroundColor:[UIColor blackColor]];
scrollview.contentSize = CGSizeMake(768, 1024);
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 500, 100)];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyDone;
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
textField.returnKeyType = UIReturnKeyDone;
[textField setUserInteractionEnabled:YES];
[textField setEnabled:YES];
[scrollview addSubview:textField];
// Here I need to show the cursor without showing keyboard
UIView* dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
((UITextField*)textField).inputView = dummyView;
[((UITextField*)textField) becomeFirstResponder];
Quelqu'un a-t-il pensé comment résoudre ce problème?
Réponses:
3 pour la réponse № 1Je pense que cela est dû à la vue du clavier, dont la hauteur est de 1. Donc, si vous changez de ligne
UIView* dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
à
UIView* dummyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
ça va marcher.