Ionic3 加用Loading效果后苹果手机(iOS)经常没法滑动,强制浏览器渲染Dom文档 (备忘)

175 篇文章 1 订阅
139 篇文章 0 订阅

问题描述
       当页面加上loadingCtrl动画效果等待异步返回后loadingCtrl已释放,但苹果手机(iOS)经常计算Content高度有误,导致明明超出一屏的内容无法上、下滑动,安卓和PC上均能正常滑动;

方案一:
参考:Javascript 强制浏览器渲染Dom文档
[html]

<ion-content #content>

[ts]

@ViewChild("content") content: Content;
    private _contentHeight = undefined;

     // Loading效果后苹果手机经常没法滑动,强制浏览器渲染Dom文档            
     if (this.appService.platForm == "ios" && this.pageIndex == 1) {
         setTimeout(() => {
             this._contentHeight = this.content.contentHeight;
         }, 500);
     }

方案二:
参考:【技巧】ionic3中content的resize知多少
[html]

<ion-content #content>

<ion-footer>
    <div style="min-height: 5px;" *ngIf="_contentHeight==undefined">-</div>
</ion-footer>

[ts]

import { ..., Content} from 'ionic-angular';

    @ViewChild("content") content: Content;
    private _contentHeight = undefined;

                // Loading效果后苹果手机经常没法滑动,强制浏览器渲染Dom文档            
                if (this.appService.platForm == "ios" && this.pageIndex == 1) {
                    this._contentHeight = undefined; 
                    setTimeout(() => {
                        this._contentHeight = this.content.contentHeight;
                    }, 500);
                }

方案三:(推荐
参考:
1、Angular变化检测机制:改善的脏检查

 2、angular 有关侦测组件变化的 ChangeDetectorRef 对象 (简洁、清晰)

[html]
无须改动
[ts]
 

import { ..., ChangeDetectorRef } from '@angular/core';

    constructor(
        ... 
        public changeDetectorRef: ChangeDetectorRef,
    ) {
        ....
    }

        this.appService.callBo("MallOrderBO", "GetOrderList", params, showLoading).subscribe(res => {
            if (res.ErrCode == 0) {
                ... 
                // Loading效果后苹果手机经常没法滑动,强制浏览器渲染Dom文档            
                if (this.appService.platForm == "ios" && this.pageIndex == 1) {
                    this.changeDetectorRef.detach();
                    setTimeout(() => {
                        this.changeDetectorRef.reattach();
                    }, 500);
                }
            } else {
                this.utils.showError(res.ErrMsg);
            }
        });



注意:
setTimeout 的间隔设为500毫秒,试过300毫秒感觉太少

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值