第一次调用 becomeFirstResponder 时,速度很慢。 Instruments 测量大约 160 毫秒......当它完成加载所有它必须加载的东西以便在屏幕上显示键盘时,键盘就会出现!杀死大部分流畅的动画。
然而,第二次,它的速度非常快!只需 2 毫秒!
那么,我能以某种方式做到这一点吗?
最佳答案
使用 GCD
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// heavy lifting here
dispatch_async(dispatch_get_main_queue(), ^{
[someTextField becomeFirstResponder];
});
});
这最初并没有按预期工作,但在将 GCD 应用于后台发生的某些“提升”后,它确实工作了。就我而言,这是一个 ScrollView
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// heavy lifting here
dispatch_async(dispatch_get_main_queue(), ^{
[_tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
});
});
关于ios - 我怎样才能加快 becomeFirstResponder 的速度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17777970/