web嵌入ios相关问题

版权声明:本篇博客内容来源于本人亲身经历,属于本人原创,转载请注明出处,感谢分享~~ https://blog.csdn.net/hl_qianduan/article/details/85005983

1、rem布局

 var fonSize = 0;
    (function (doc, win) {
        var docEl = doc.documentElement,
            resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
            recalc = function () {
                var clientWidth = docEl.clientWidth;
                if (!clientWidth) return;
                fonSize = 100 * (clientWidth / 750);//按照750px的设计稿
                docEl.style.fontSize = 100 * (clientWidth / 750) + 'px';
            };

        // Abort if browser does not support addEventListener
        if (!doc.addEventListener) return;
        win.addEventListener(resizeEvt, recalc, false);
        doc.addEventListener('DOMContentLoaded', recalc, false);
    })(document, window);

2、页面之前传递参数,可以用jquery.params.js(在我另一篇文章有)

3、ios与web之间事件方法传递需要一个桥接的方式:用于在UIWebViews / WebViews中的Obj-C和JavaScript之间发送消息的iOS / OSX桥——WebViewJavascriptBridge

作为一只前端工程狮,我只讲web这边需要写的:

function setupWebViewJavascriptBridge(callback) {
	if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
	if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
	window.WVJBCallbacks = [callback];
	var WVJBIframe = document.createElement('iframe');
	WVJBIframe.style.display = 'none';
	WVJBIframe.src = 'https://__bridge_loaded__';
	document.documentElement.appendChild(WVJBIframe);
	setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
}

setupWebViewJavascriptBridge(function(bridge) {
	
    /* 初始化 */
	/* Initialize your app here */

	bridge.registerHandler('JS Echo', function(data, responseCallback) {
		console.log("JS Echo called with:", data)
		responseCallback(data)
	})
	bridge.callHandler('ObjC Echo', {'key':'value'}, function responseCallback(responseData) {
		console.log("JS received response:", responseData)
	})
})

3、设计字体小于12px

transform: scale(0.7);

猜你喜欢

转载自blog.csdn.net/hl_qianduan/article/details/85005983