如何用html构建ios应用,使用HTML5构建iOS原生APP(5)

我的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中做好宽度自适应:

备注

介绍一下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.

我写字的地方迁移到公众号啦~欢迎关注我的公众号:余果专栏

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值