菜鸟教程小白 发表于 2022-12-12 10:29:15

ios - 无法从一个 TextInput 点按到另一个


                                            <p><p>当我专注于一个 <code>TextInput</code> 时,点击另一个 <code>TextInput</code> 字段并没有达到我的预期(更改 <strong>focus</strong>到那个 <code>TextInput</code>)。</p>

<p>相反,它只是<strong>模糊</strong>当前的<code>TextInput</code>,需要<strong>第二次点击以聚焦</strong>下一个<code>TextInput</code>。 </p>

<p>有没有办法做到这一点,或者这是 <strong>React Native</strong> 目前的缺点?</p>

<p>示例代码:</p>

<pre><code>class MyTest extends Component {
render() {
    return (
      &lt;ScrollView style={styles.container}&gt;
      &lt;View&gt;
          &lt;TextInput style={styles.textInput} /&gt;
          &lt;TextInput style={styles.textInput} /&gt;
      &lt;/View&gt;
      &lt;/ScrollView&gt;
    );
}
}

const styles = StyleSheet.create({
container: {
    flex: 1,
    backgroundColor: &#39;#ddd&#39;,
    paddingTop: 64
},
textInput: {
    backgroundColor: &#39;#fff&#39;,
    borderColor: &#39;#000&#39;,
    borderWidth: 1,
    height: 46,
    paddingLeft: 10
}
});
</code></pre>

<p>原来,当输入字段在 ScrollView 中时,它们的行为与我上面描述的一样(您不能只从一个字段点击到另一个字段)。我尝试将 TextInputs 包装在 View 中以解决此问题,但没有成功。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>你需要给你添加<code>keyboardShouldPersistTaps={true}</code> <a href="https://facebook.github.io/react-native/docs/scrollview.html" rel="noreferrer noopener nofollow">ScrollView</a> .</p>

<blockquote>
<p><strong>keyboardShouldPersistTaps bool:</strong></p>

<p><em>When false, tapping outside of the focused text input when the keyboard is up dismisses the keyboard. When true, the scroll view will
not catch taps, and the keyboard will not dismiss automatically. The
default value is false.</em></p>
</blockquote></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 无法从一个 TextInput 点按到另一个,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/35354099/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/35354099/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 无法从一个 TextInput 点按到另一个