我的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.