UIWebView横向旋转不填充视图
我有我的UIWebView的问题。 当视图加载它在任何方向加载罚款,完美填充整个页面等
但是,如果我加载它的肖像,然后旋转设备的Web视图不会填满整个右侧,我不能为我的生活弄清楚为什么。
这是我的观点做加载方法
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait){ self.measurementsWebView.frame = CGRectMake(0, 0, 320, 367); }else if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight){ self.measurementsWebView.frame = CGRectMake(0, 0, 480, 218); } NSString *path = [[NSBundle mainBundle] pathForResource:@"measurements" ofType:@"png"]; [measurementsWebView loadHTMLString:[NSString stringWithFormat:@"<html><body><img src=\"file://%@\"></body></html>",path] baseURL:nil]; measurementsWebView.scalesPageToFit = YES; }
如果我在接口生成器中查找,我正在试图find允许我设置扩展宽度的面板,或者是你所谓的,但是我只能看到这个。
任何帮助将不胜感激
不要手动设置框架,也可以将自动resize的掩码设置为:
measurementsWebView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
这将调整webView的大小,以防在屏幕上没有其他元素(我没有,从调整measurementsWebView
值WebView时使用的measurementsWebView
)。 或者,如下图所示,直接从笔尖:
可以通过点击左下angular的Autosizing框中的红色条来设置蒙版。
viewDidLoad
运行一次 – 加载视图时。
如果要在旋转发生时手动调整框架,请添加代码以将其大小调整为视图旋转时调用的viewDidLayoutSubviews
。
-(void)viewDidLayoutSubviews { [super viewDidLayoutSubviews]; self.measurementsWebView.frame = self.view.bounds; }
在界面生成器中,在下拉菜单中显示“布局矩形”,点击它并select“矩形框”。
或者,您可以重写视图控制器中的willAnimateRotationToInterfaceOrientation:
方法,并像在viewDidLoad
那样手动设置坐标/大小。