在我的 iPhone 应用程序中,我有一个带有多个 UITextField 的 UIScrollView。
使用 BSKeyboardControls 我添加了 Prev/Next/Done 按钮以在字段之间移动。但是,所选字段上的焦点不起作用,这意味着文本字段实际上仍在键盘下方,尽管已选中。
becomeFirstResponder
已激活,但只是不设置焦点。
有什么想法可能是错的吗?
谢谢
在 H 文件中
#import "BSKeyboardControls.h"
...
@interface AddClientViewController : BaseViewController<UIAlertViewDelegate, UIScrollViewDelegate, UIPickerViewDelegate, UIPickerViewDataSource, UITextFieldDelegate, UITextViewDelegate, BSKeyboardControlsDelegate>
...
@property (strong, nonatomic) IBOutlet UITextField *firstName;
@property (strong, nonatomic) IBOutlet UITextField *lastName;
@property (strong, nonatomic) IBOutlet UITextField *email;
@property (strong, nonatomic) IBOutlet UITextField *mobile;
@property (strong, nonatomic) IBOutlet UITextField *birthday;
@property (strong, nonatomic) IBOutlet UITextField *anniversary;
@property (strong, nonatomic) IBOutlet UITextField *street;
@property (strong, nonatomic) IBOutlet UITextField *city;
@property (strong, nonatomic) IBOutlet UITextField *state;
@property (strong, nonatomic) IBOutlet UITextField *zip;
@property (strong, nonatomic) IBOutlet UIScrollView *scrollView;
@property (nonatomic, strong) BSKeyboardControls *keyboardControls;
....
在 M 文件中
- (void)viewDidLoad
{
...
NSArray *fields = @[ self.firstName, self.lastName,
self.email, self.mobile,
self.birthday, self.anniversary,
self.street, self.city, self.state, self.zip];
[self setKeyboardControls:[[BSKeyboardControls alloc] initWithFields:fields]];
[self.keyboardControls setDelegate:self];
}
- (void)keyboardControlsDonePressed:(BSKeyboardControls *)keyboardControls
{
[keyboardControls.activeField resignFirstResponder];
}
- (void)keyboardControls:(BSKeyboardControls *)keyboardControls directionPressed:(BSKeyboardControlsDirection)direction
{
UIView *view = keyboardControls.activeField.superview.superview;
[self.scrollView scrollRectToVisible:view.frame animated:YES];
}
- (void)keyboardControls:(BSKeyboardControls *)keyboardControls selectedField:(UIView *)field inDirection:(BSKeyboardControlsDirection)direction
{
UIView *view = keyboardControls.activeField.superview.superview;
[self.scrollView scrollRectToVisible:view.frame animated:YES];
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
[self.keyboardControls setActiveField:textField];
}
- (void)textViewDidBeginEditing:(UITextView *)textView
{
[self.keyboardControls setActiveField:textView];
}
BSKeyboardControls 中的 setActiveField
- (void)setActiveField:(id)activeField
{
if (activeField != _activeField)
{
if ([self.fields containsObject:activeField])
{
_activeField = activeField;
if (![activeField isFirstResponder])
{
[activeField becomeFirstResponder];
}
[self updateSegmentedControlEnabledStates];
}
}
}