PHONEGAP的一些设置

来源:互联网 发布:实时抓取网页数据 编辑:程序博客网 时间:2024/05/17 13:42

1. 隐藏顶部的状态栏
在xxx-Info.plist中新增一项属性:"Status bar is initially hidden" = YES;此外,还可以增加其他的属性,例如Launch image等。

2. 用户滑动Webview时,正常情况下会超出边界然后弹回来,也就是Bounce,可以通过Cordova.plist中的属性来实现了。
*对于老版本的,在AppDelegate.m中的webViewDidFinishLoad方法中添加:
{syntaxhighlighter brush:shell}
for (id subview in theWebView.subviews)
if ([[subview class] isSubclassOfClass: [UIScrollView class]])
((UIScrollView *)subview).bounces = NO;
{/syntaxhighlighter}

3. Phonegap 内购 IAP插件
https://github.com/phonegap/phonegap-plugins/tree/master/iPhone/InAppPurchaseManager

4. 修改Bounce时的背景色
{syntaxhighlighter brush:shell}
theWebView.backgroundColor = [UIColorgrayColor];
{/syntaxhighlighter}

5. Phonegap的deviceready事件通常要比DOMContentLoaded后触发。

Webkit相关

1. 防止页面一定位数的数字自动变成链接
当页面上存在一定位数的数字(例如8位)时,会突然自己变成链接,实际上是被webkit自动解析成电话号码了,可以通过以下方式禁止:
在Classes中的AppDelegate.m中的webViewDidStartLoad中添加
{syntaxhighlighter brush:shell}
theWebView.dataDetectorTypes = UIDataDetectorTypeNone;
{/syntaxhighlighter}
如果是在Safari中则可以通过添加相关的meta标签来设置,而在phonegap中则只能修改OC代码。

2. 阻止a标签长按后打开提示框
长按A标签后,iOS会从底部弹出一个列表,允许你选择以何种方式打开,如果要禁止这种提示时,可以添加下列css属性:
{syntaxhighlighter brush:css}
-webkit-touch-callout:none
{/syntaxhighlighter}

3. 长按A标签会造成一定区域出现“蒙板式”的阴影,解决方案是添加以下的CSS代码(只在ipad和iphone中有效)
{syntaxhighlighter brush:css}
*{
-webkit-touch-callout: none; /* prevent callout to copy image, etc when tap to hold */
-webkit-text-size-adjust: none; /* prevent webkit from resizing text to fit */
-webkit-tap-highlight-color: rgba(0,0,0,0); /* make transparent link selection, adjust last value opacity 0 to 1.0 */
-webkit-user-select: none; /* prevent copy paste, to allow, change 'none' to 'text' */
}
{/syntaxhighlighter}

4. 监听视频播放时的全屏事件
{syntaxhighlighter brush:shell}
// 进入全屏
video.bind( ‘webkitbeginfullscreen’, function() {
alert( ‘begin’ );
} );

// 结束全屏
video.bind( ‘webkitendfullscreen’, function() {
alert( ‘end’ );
} );
{/syntaxhighlighter}