打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
使用HTML5构建iOS原生APP(5)

使用HTML5构建iOS原生APP(5)

更多 0

我的app基本上是由一个原生的navigation controller贯穿全局,然后在每一个scene中都有一个主要的UIWebView作为主要逻辑:

- (void)viewDidLoad{	...	self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(.0f, 0.f, self.view.bounds.size.width, self.view.bounds.size.height -44)];//-44是减去标题栏高度	self.webView.delegate = self;	...	[self.view addSubview:self.webView];}

现在的问题是,当手机翻转的时候,webView的大小不会重绘,就会出现bug,解决办法很简单,就是实现翻转委托:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {    	NSLog(@"I have finished rotating");	self.webView.frame = CGRectMake(.0f, 0.f, self.view.bounds.size.width, self.view.bounds.size.height));}

就可以了,然后在webView中做好宽度自适应:

<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scable=0, minimun-scale=1.0, maximum-scale=1.0">

备注

介绍一下view的三种坐标属性:

Frame A view’s frame (CGRect) is the position of its rectangle in the superview’s coordinate system. By default it starts at the top left.

Bounds A view’s bounds (CGRect) expresses a view rectangle in its own coordinate system.

Center A center is a CGPoint expressed in terms of the superview’s coordinate system and it determines the position of the exact center point of the view.

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
完美方案
[转载]CGRectInset、CGRectOffset、等对比整理
ios view的frame和bounds之区别(位置和大小)
[转载]UIView中bounds和frame的差别
iOS: Frame VS Bounds Or How To Resize Your Basic UITableView Cell
iOS开发 Orientation 屏幕旋转
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服