引自:http://stackoverflow.com/questions/19209781/ios-7-status-bar-with-phonegap

情景:在ios7下PhoneGap app会上移20px从而被状态栏挡住,查找了些方法后可以解决这问题,但是拍照完返回界面后仍然会出现上移20px的情况,参考了链接后,最终解决方法如下:

in  AppDelegate.m  //兼容启动页上移20px

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
CGRect screenBounds = [[UIScreen mainScreen] bounds]; #if __has_feature(objc_arc)
self.window = [[UIWindow alloc] initWithFrame:screenBounds];
#else
self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease];
#endif
self.window.autoresizesSubviews = YES; #if __has_feature(objc_arc)
self.viewController = [[MainViewController alloc] init];
#else
self.viewController = [[[MainViewController alloc] init] autorelease];
#endif
self.viewController.useSplashScreen = YES; // Set your app's start page by setting the <content src='foo.html' /> tag in config.xml.
// If necessary, uncomment the line below to override it.
// self.viewController.startPage = @"index.html"; // NOTE: To customize the view's frame size (which defaults to full screen), override
// [self.viewController viewWillAppear:] in your view controller. self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
[application setStatusBarStyle:UIStatusBarStyleLightContent];
self.window.clipsToBounds = YES;
self.window.frame = CGRectMake(0, 20, self.window.frame.size.width, self.window.frame.size.height-20);
} return YES;
}

In MainViewController.h:

@interface MainViewController : CDVViewController
@property(atomic)BOOL viewSizeChanged;
@property(atomic)int number;
@end

In MainViewController.m:

@implementation MainViewController
@synthesize viewSizeChanged;
@synthesize number;
[...]
- (id)init
{
self = [super init];
if (self) {
self.viewSizeChanged=NO;
self.number=0;
// Uncomment to override the CDVCommandDelegateImpl used
// _commandDelegate = [[MainCommandDelegate alloc] initWithViewController:self];
// Uncomment to override the CDVCommandQueue used
// _commandQueue = [[MainCommandQueue alloc] initWithViewController:self];
}
return self;
} [...]
- (void)viewWillAppear:(BOOL)animated
{
// View defaults to full size. If you want to customize the view's size, or its subviews (e.g. webView),
// you can do so here.
//Lower screen 20px on ios 7
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= && !self.viewSizeChanged) {
if (self.number==1) {
CGRect viewBounds = [self.webView bounds];
viewBounds.origin.y = ;
viewBounds.size.height = viewBounds.size.height - ;
self.webView.frame = viewBounds;
self.viewSizeChanged = YES;
} self.number=1;
}
[super viewWillAppear:animated];
}

Now for the viewport problem, in your deviceready event listener, add this (using jQuery):

 if (window.device && parseFloat(window.device.version) >= 7) {
$(window).on('orientationchange', function () {
var orientation = parseInt(window.orientation, 10);
// We now the width of the device is 320px for all iphones
// Default height for landscape (remove the 20px statusbar)
var height = 300;
// Default width for portrait
var width = 320;
if (orientation !== -90 && orientation !== 90 ) {
// Portrait height is that of the document minus the 20px of
// the statusbar
height = document.documentElement.clientHeight - 20;
} else {
// This one I found experimenting. It seems the clientHeight
// property is wrongly set (or I misunderstood how it was
// supposed to work).
// Dunno if it's specific to my setup.
width = document.documentElement.clientHeight + 20;
}
document.querySelector('meta[name=viewport]')
.setAttribute('content',
'width=' + width + ',' +
'height=' + height + ',' +
'initial-scale=1.0,maximum-scale=1.0,user-scalable=no');
})
.trigger('orientationchange');
}

Here is the viewport I use for other versions:

 <meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1.0,maximum-scale=1.0" />

测试结果:完美解决。

PhoneGap 兼容IOS上移20px(包括启动页,拍照)的更多相关文章

  1. 用Flutter开发的跨平台项目,完美运行在Android和IOS上,Material简洁风格,包括启动页、引导页、注册、登录、首页、体系、公众号、导航、项目,还有漂亮的妹子图库,运行极度流畅,结构清晰,代码规范,值得拥有

    Flutter学习资源汇总持续更新中...... Flutter官方网站 Flutter中文网 wendux的Flutter实战 Flutter官方exampleflutter_gallery 阿里巴 ...

  2. [摘抄]iOS App icon、启动页、图标规范

    以下内容都是我在做App时通过自己的经验和精品的分析得来的,希望会帮助到你.但是有时个别情况也要个别分析,要活学活用. 一. App  Icon 在设计iOS App Icon时,设计师不需要切圆角, ...

  3. phonegap ios默认启动页

    phonegap创建的项目默认的启动界面是phonegap的图标,想去掉这个图标,有两个方法,第一就是将resourece下面的splash文件下面的图片改成自己想要的启动页面,名字要相同,替换掉它默 ...

  4. 【IOS】模仿"抽屉新热榜"动态启动页YFSplashScreen

    IOS最好要设置系统默认启动页面,不然进入应用就会突然闪现黑色画面 下图是我们要实现的效果: 总体思路:设置一个系统默认启动页面,在进入didFinishLaunchingWithOptions时, ...

  5. iOS启动页设置

    点击项目->TARGETS->App Icons and Launch Images->Launch Images Source->Use Asset Catalog...-& ...

  6. [iOS]利用Appicon and Launchimage Maker生成并配置iOSApp的图标和启动页

    一.先来研究下这个软件->Appicon and Launchimage Maker 首先打开你电脑上的AppStore,然后搜索:AppIcon 然后回车: 这里我们先使用免费版的点击下载.( ...

  7. iOS LaunchScreen设置启动图片,启动页停留时间

    [新建的iOS 项目启动画面默认为LaunchScreen.xib] 如果想实现一张图片作为启动页,如下图

  8. iOS开发 关于启动页和停留时间的设置

    引言: 在开发一款商业App时,我们大都会为我们的App设置一个启动页. 苹果官方对于iOS启动页的设计说明: 为了增强应用程序启动时的用户体验,您应该提供一个启动图像.启动图像与应用程序的首屏幕看起 ...

  9. iOS LaunchScreen设置启动图片 启动页停留时间

    问题:想实现类似微信启动页一样 设置为一个整页面的图片 问题二:iOS启动页面怎样设置多停留一会 新建的iOS 项目启动画面默觉得LaunchScreen.xib 假设想实现一张图片作为启动页,例如以 ...

随机推荐

  1. Atitit.  c# 语法新特性 c#2.0 3.0 4.0 4.5 5.0 6.0   attilax总结

    Atitit.  c# 语法新特性 c#2.0 3.0 4.0 4.5 5.0 6.0   attilax总结 1.1. C# 1.0-纯粹的面向对象 1.2. C# 2.0-泛型编程新概念 1.3. ...

  2. C#协变与逆变

    http://zh.wikipedia.org/wiki/%E5%8D%8F%E5%8F%98%E4%B8%8E%E9%80%86%E5%8F%98 协变与逆变是程序设计语言中的类型系统的一对概念.类 ...

  3. 怎样优雅的研究 RGSS3 番外(一) ruby 实现的后缀自己主动机

    *我真的不会 ruby 呀* #encoding:utf-8 #==================================================================== ...

  4. script 标签里的 async 和 defer

    无 async 和 defer 浏览器立即加载并执行指定脚本(读到即加载并执行),阻塞文档解析 async 脚本的加载执行和文档的加载渲染 并行. defer 脚本的加载和文档的加载渲染并行,但脚本的 ...

  5. iOS_25_彩票骨架搭建+导航栏适配

    终于效果图: Main.storyboard 初始化的控制器是:导航控制器 它的根控制器是:TabBarController TabBarController的底部是一个自己定义的TabBar 里面加 ...

  6. STL next_permutation(a,a+n) 生成一个序列的全排列。满足可重集。

    /** 题目: 链接: 题意: 思路: */ #include <iostream> #include <cstdio> #include <vector> #in ...

  7. Spring MVC文本框

    以下示例显示如何使用Spring Web MVC框架在表单中使用文本框.首先使用Eclipse IDE来创建一个Web工程,按照以下步骤使用Spring Web Framework开发基于动态表单的W ...

  8. redis的下载

    网址一:https://github.com/dmajkic/redis/downloads 网址二:http://windows.php.net/downloads/pecl/releases/re ...

  9. 最新win7系统安全稳定版

    最新win7系统32位安全稳定版 V2016年2月,具有更安全.更稳定.更人性化等特点.集成最常用的装机软件,集成最全面的硬件驱动,精心挑选的系统维护工具,加上萝卜独有人性化的设计.是电脑城.个人.公 ...

  10. 服务器之FRU

    EEPROM是server主板上的电可擦除可编程只读存储器, 里面存储了FRU data, 包括制造商,产品型号,产品序列号,资产序列号等信息,为厂商和客户提供资产信息管理. 所以正确的FRU格式以及 ...