在我的程序中,我在xib上创建了一个自定义视图,并希望使用textField.inputView
之类的视图。当KeyboardWillShow
时,我想更改inputView框架,但是当我点击此textField时,UIKeyboardWillShowNotification
不起作用。我如何更改textField.inputView
或强迫工作UIKeyboardWillShowNotification
?
- (void)viewDidLoad {
[super viewDidLoad];
CGRect rect = CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 0);
self.actionView = [[ActionView alloc] initWithFrame:rect];
self.actionView.delegate = self;
self.currencyTextField.inputView = self.actionView;
[self layout];
}
- (void)addObserver{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShown:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillHide:)
name:UIKeyboardWillHideNotification
object:nil];
}
- (void)keyboardWillShown:(NSNotification *)notification{
NSDictionary* keyboardUserInfo = [notification userInfo];
CGSize keyboardSize = [[keyboardUserInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;
self.actionView.frame = CGRectMake(0, 0, keyboardSize.width, keyboardSize.height);
[self.currencyTextField reloadInputViews];
}
答案 0 :(得分:0)
您需要一个非零高度
CGRect rect = CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 100);
也别忘了打电话
[self addObserver];
viewDidLoad
的结尾