Cordova iOSアプリケーションでの間違ったカーソル位置に影響を与えるIFrameのズーム
-
26-12-2019 - |
質問
私はIOS開発のためにCordovaを使っています。IFrameを使用して、私のアプリで外部リンクを開きます。外部ページサイズは大きく、画面に収まるように、-WebKit-Transform Scaleプロパティを使用しています。すべてが元気で、画面に収まります。しかし、問題は、テキスト入力を選択すると、入力カーソル(キャレット)がテキストフィールドの下のどこかに点滅し始めることです。
コードを見てください:
index.html:
<div data-role="page" id="personDetailPage">
<div data-role="header" class="header" >
<div class="logo" id="mainScreenLogo"> <img src="" id="headerLogoImg" /> </div>
<h1 id="personDetailTitle"class="tittle">Person Detail</h1>
<a href="#main" class="ui-btn-right headerHomeIcon" data-transition="slide" onclick="formHomeButtonClick();"> <img src="homeIcon.png" class="headerHomeImg" /> </a>
</div>
<div id="iFrameDiv" scrolling="no">
<iframe id="formframe" width="280" height="150" src="form.html" onLoad='fixiFrame();' frameborder="0" ></iframe>
</div>
</div>
.
form.html:
<div data-role="page" id="personRegistration" scrolling="no"><br>
Please Enter the Person Details
<form id="registrationForm" method="POST" action="https://abe.com/Registration.aspx" onsubmit="return checkform();" >
<div data-role="fieldcontain" class="ui-hide-label">
<input type="text" name="name" id="name" value="" placeholder="Name" />
</div>
<div data-role="fieldcontain" class="ui-hide-label"> <input type="text" name="email" id="email" value="" placeholder="Email" />
</div>
<a href="" id="my-custom-button-registration" data-role="button" data-transition="fade" onclick="return checkform();">Continue</a>
</form>
</div>
.
とjsは:
function fixiFrame() { // set the size of IFrame to the device screen fit
$("#formframe").width( viewport.width );
$("#formframe").height( viewport.height -35- deviceVarient );
}
function resizeIframe(){ //zoom the person registration Iframe upto screen fit it will be called when device ready
var xaix = viewport.width /widthFactor; // widthFactor is the actual page sixe of external page i.e; abc.com/Registration.aspx
var yaix = (viewport.height-35- $(".logo").height() ) /heightFactor;
$('#formframe').css('-webkit-transform', 'scale('+xaix+','+yaix+')');
$('#formframe').css('-webkit-transform-origin', '0 0');
//alert('resizeIframe(): xaix = '+xaix+' yaix = '+yaix+' $(.logo).height() = '+$(".logo").height()); //for testing & debugging
}
. 解決
これは私にも直面していた昔の問題でした。私はこの問題の解決策のための私の2歳のコードを調べました、そしてここで解決策です。
外部リンクを開くために iframe
を使用する代わりに、外部リンクを開くために inAppBrowser
を使用しました。
window.open( encodeURI('externalPage.html') , '_blank', 'location=no','EnableViewPortScale=yes');
今、 'enableviewportscale= yes' オプションを行うものです。 browserOptions.enableviewportscale
メソッドで使用されている true
メソッドにCDVInAppBrowser.m
をopenInInAppBrowser
に設定します。すなわち;
self.inAppBrowserViewController.webView.scalesPageToFit = browserOptions.enableviewportscale;
.
それは上記の線が置き換えられることを意味します
UIWebView
options
は、実際には、アスペクト比を考慮してページ幅にページにフィットするプロパティ self.inAppBrowserViewController.webView.scalesPageToFit = YES;
があります。