我参考官方Demo(HBuilder-Integrate)在Xcode搭建了一个项目,使用 WebView集成方式 打开页面,正常,
使用 WebApp集成方式运行,界面黑屏,使用Reveal查看元素,发现 PDRCoreAppFrame 的度和高都是0,所以界面展示成黑屏,如果在Reveal中设置PDRCoreAppFrame的宽高后,界面元素又展示出来了,
采用 WebApp集成方式 时,为什么 PDRCoreAppFrame 布局的宽高是0?代码都是参考官方Demo项目代码
代码如下:
PDRCore *h5Engine = [PDRCore Instance];
[self setStatusBarStyle:h5Engine.settings.statusBarStyle];
// 获取当前是否是全屏
_isFullScreen = [UIApplication sharedApplication].statusBarHidden;
if ( _isFullScreen != h5Engine.settings.fullScreen ) {
_isFullScreen = h5Engine.settings.fullScreen;
if ( [self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)] ) {
[self setNeedsStatusBarAppearanceUpdate];
} else {
[[UIApplication sharedApplication] setStatusBarHidden:_isFullScreen];
}
}
CGRect newRect = self.view.bounds;
if ( [self reserveStatusbarOffset] && [PTDeviceOSInfo systemVersion] > PTSystemVersion6Series) {
if ( !_isFullScreen ) {
newRect.origin.y += kStatusBarHeight;
newRect.size.height -= kStatusBarHeight;
}
_statusBarView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, newRect.size.width, kStatusBarHeight+1)];
_statusBarView.backgroundColor = h5Engine.settings.statusBarColor;
_statusBarView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.view addSubview:_statusBarView];
}
_containerView = [[UIView alloc] initWithFrame:newRect];
_containerView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
// 设置5+内核的Delegate,5+API在修改状态风格和应用是否全屏时会调用
h5Engine.coreDeleagete = self;
h5Engine.persentViewController = self;
[self.view addSubview:_containerView];
// 设置WebApp所在的目录,该目录下必须有mainfest.json
NSString* pWWWPath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"Pandora/apps/MEBDcloudDemo/www"];
// 如果路径中包含中文,或Xcode工程的targets名为中文则需要对路径进行编码
//NSString* pWWWPath2 = (NSString *)CFURLCreateStringByAddingPercentEscapes( kCFAllocatorDefault, (CFStringRef)pTempString, NULL, NULL, kCFStringEncodingUTF8 );
// 用户在集成5+SDK时,需要在5+内核初始化时设置当前的集成方式,
// 请参考AppDelegate.m文件的- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions方法
if ([[PDRCore Instance] respondsToSelector:@selector(startAsAppClient)]) {
[[PDRCore Instance] performSelector:@selector(startAsAppClient)];
}
// 设置5+SDK运行的View
[[PDRCore Instance] setContainerView:_containerView];
// 传入参数可以在页面中通过plus.runtime.arguments参数获取
NSString* pArgus = @"id=plus.runtime.arguments";
// 启动该应用
pAppHandle = [[[PDRCore Instance] appManager] openAppAtLocation:pWWWPath withIndexPath:@"tab-webview-main.html" withArgs:pArgus withDelegate:nil];
运行效果:
Reveal界面元素布局:
通过Reveal调整界面元素布局:
模拟器运行效果:
如烟OA
请问你解决了吗?
2017-04-28 18:42