我有一个发送消息的模态,为了让键盘显示,我必须在触发模态后将焦点设置在textarea上.
- <script id="new-post.html" type="text/ng-template">
- <div class="modal">
- <form ng-submit="sendPost(post)">
- <ion-header-bar class="bar-royal">
- <button class="button button-clear button-light" ng-click="closeNewPost()">Cancel</button>
- <h1 class="title">New Message</h1>
- <button type="submit" class="button button-clear">Post</button>
- </ion-header-bar>
- <ion-content>
- <div class="list">
- <label class="item item-input">
- <textarea class="textareas" id="postMessageInput" ng-model="$parent.post.message" placeholder="What do you want to say?" autofocus ></textarea>
- </label>
- </div>
- </ion-content>
- </form>
- </div>
控制器:
- $ionicModal.fromTemplateUrl('new-post.html',function(modal) {
- $scope.postModal = modal;
- },{
- scope: $scope,focusFirstInput: true
- });
- $scope.newPost = function() {
- $scope.postModal.show().then(document.getElementById('postMessageInput').focus());
- };
会发生的是模态首先向上滑动,然后键盘向上滑动.当模态首次显示时,屏幕有时闪烁.整个经历根本不顺利.有时,textarea甚至被推到模态标题下.
理想情况下,我希望模式使用已在视图上呈现的键盘向上滑动,就好像键盘嵌入到模态中一样.这就是其他应用程序(ios)的工作原理.这是可能的,还是有标准方法用键盘和textarea显示模态?
我通过将屏幕禁用设置为true来修复屏幕闪烁:
- cordova.plugins.Keyboard.disableScroll(true)