3

我有一个只有一个文本字段的应用程序,我希望该文本字段在视图加载时激活,并且键盘处于活动状态。

有什么办法可以强制吗?

詹姆士

4

4 回答 4

2

让它成为第一响应者。有关 Apple 的教程,请参阅此链接

于 2010-07-10T06:26:42.147 回答
1

简单的

[self.myTextView becomeFirstResponder];
于 2012-06-27T11:20:15.127 回答
1

在 Swift 中,你可以让它成为第一响应者

textField.becomeFirstResponder()

https://developer.apple.com/documentation/uikit/uiresponder/1621113-becomefirstresponder

于 2018-11-30T12:20:01.633 回答
0

将对象称为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..
    }];
}];   
于 2014-11-20T01:21:58.863 回答