html5 实现ios原生控件,使用HTML5构建iOS原生APP(5)

本文介绍了在iOS应用中,UIWebView在设备旋转时不会自动调整大小的问题,导致显示异常。作者提供了简单的解决办法,即监听设备方向变化并重新设置webView的frame。同时,还讲解了view的frame、bounds和center三个坐标属性的概念,帮助理解视图坐标系统。
摘要由CSDN通过智能技术生成

我的app基本上是由一个原生的navigation controller贯穿全局,然后在每一个scene中都有一个主要的UIWebView作为主要逻辑:-(void)viewDidLoad{...self.webView=[[UIWebViewalloc]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、付费专栏及课程。

余额充值