When using ionic to develop WeChat for IOS system, there will be a problem. When filling out the form, the keyboard will block the input box. In fact, it is not a big problem. As long as the user enters a word, he can see the input box immediately.
Unfortunately, some customers are unreasonable and don’t care about this problem. Anyway, they just can’t do it. So they suddenly woke up while sleeping one day and came up with this plan.
I won't talk about the code carefully, just go to the picture
angular.module('MyApp').directive('focusInput', ['$ionicScrollDelegate', '$window', '$timeout', '$ionicPosition', function ($ionicScrollDelegate, $window, $timeout, $ionicPosition) {return {restrict: 'A',scope: false,link: function ($scope, iElm, iAttrs, controller) {if (ionic.Platform.isIOS()) {iElm.on('focus', function () {var top = $ionicScrollDelegate.getScrollPosition().top;var eleTop = ($ionicPosition.offset(iElm).top) / 2var realTop = eleTop + top;$timeout(function () {if (!$scope.$last) {$ionicScrollDelegate.scrollTo(0,realTop);} else {try {var aim = angular.element(document).find('.scroll')aim.css('transform', 'translate3d(0px,' + '-' + realTop + 'px, 0px) scale(1)');$timeout(function () {iElm[0].focus();console.log(2);}, 100)} catch (e) {}}}, 500)})}}}}])