[英]How can I perform a check on all check UITextField's in if condition
first your make sure that all textField have their delegate set to self ( means your viewController) 首先,请确保所有textField的委托都设置为self(表示您的viewController)
Ex. [myTextField setDelegate:self];// you can also set the delegate in Storyboard or xib directly
Then add a instance variable in your class implementation like - 然后在类实现中添加实例变量,例如-
@implementation myViewController
{
UITextField *activeField;
}
and then simply implement the method as below 然后只需实现以下方法
in your textFieldShouldBeginEditing, set activeField 在您的textFieldShouldBeginEditing中,设置activeField
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
activeField = textField; // HERE get reference of your active field
return true;
}
There is a very nice method provided for all handling 提供了一个非常好的方法来处理所有问题
CGRectContainsRect CGRect包含Rect
if (!CGRectContainsRect(viewableAreaFrame, activeTextFieldFrame))
{
/*Scroll or move view up*/
}
Implement below in your keyboardWillShow method 在您的keyboardWillShow方法中实现以下内容
EX. 例如
- (void)keyboardWillShow:(NSNotification *)notification
{
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
float viewWidth = self.view.frame.size.width;
float viewHeight = self.view.frame.size.height;
CGRect viewableAreaFrame = CGRectMake(0.0, 0.0, viewWidth, viewHeight - keyboardHeight);
CGRect activeTextFieldFrame = [activeTextField frame];
if (!CGRectContainsRect(viewableAreaFrame, activeTextFieldFrame))
{
/*Scroll or move view up*/
[UIView animateWithDuration:0.3 animations:^{
CGRect f = self.view.frame;
f.origin.y = -keyboardSize.height;
self.view.frame = f;
}];
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.