我有一个只有一个文本字段的应用程序,我希望该文本字段在视图加载时激活,并且键盘处于活动状态。
有什么办法可以强制吗?
詹姆士
让它成为第一响应者。有关 Apple 的教程,请参阅此链接。
简单的
[self.myTextView becomeFirstResponder];
在 Swift 中,你可以让它成为第一响应者
textField.becomeFirstResponder()
https://developer.apple.com/documentation/uikit/uiresponder/1621113-becomefirstresponder
将对象称为First Responder即可。但我花了几分钟发现最好分配它..最后!
[UITextFeild becomeFirstResponder];
例如,如果您有一个动画 UIView,请在绘制视图后分配它。
[UIView animateWithDuration:0.9
animations:^{
UIView.frame = newFrame;
}
completion:^(BOOL finished){
[UIView animateWithDuration:0.9
animations:^{}
completion:^(BOOL finished){
[UITextFeild becomeFirstResponder];// << Right here..
}];
}];