我正在加载uiwebview作为子视图,当手机处于纵向状态时,它会完美地填满屏幕,如果您随后旋转设备,它将完美地填充景观。但是如果你在横向加载webview它只填充了一半的页面...我不知道如何解决这个问题..我已经尝试了很多不同的东西。
在Interface Builder中设置框架大小,灵活的高度宽度和更改设置..但我现在只是丢失了,希望有人可以告诉我需要查看的内容才能使其正常工作。
按照要求编写代码(原谅这个混乱......它到了这一点,因为我一直在尝试许多不同的东西)
// webviewviewController.m
//...
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait){
[webViewTest setBounds:CGRectMake(0.0,0.0,320.0,367.0)];
}else if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight){
[webViewTest setBounds:CGRectMake(0.0,0.0,480.0,218.0)];
}
}
//...
// displayviewController.m
if (![actionContainer superview]) {
actionContainer.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view insertSubview:actionContainer atIndex:1];
// actionContainer.frame = CGRectMake(0.0, 0.0, actionContainer.bounds.size.width, actionContainer.bounds.size.height);
// Set up and load htmlTest.View
htmlTest = [[HTMLTestViewController alloc] init];
htmlTest.view.backgroundColor = [UIColor whiteColor];
htmlTest.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
htmlTest.view.frame = CGRectMake(0.0, 0.0, htmlTest.view.bounds.size.width, htmlTest.view.bounds.size.height);
// [self.actionContainer insertSubview:htmlTest.view atIndex:0];
[actionContainer insertSubview:htmlTest.view aboveSubview:actionContainer];
actionContainer.frame = CGRectMake(0.0, 480.0, actionContainer.bounds.size.width, actionContainer.bounds.size.height);
// Load shade behind Actionview
shadeView.frame = CGRectMake(0.0, 0.0, 480.0, 480.0);
shadeView.alpha = 0.0;
[self.view insertSubview:shadeView belowSubview:actionContainer];
// Send request (change depending on the tabbar selected
// [htmlTest htmlRequest];
[UIView animateWithDuration:0.6
delay:0.0f
options:UIViewAnimationCurveEaseIn
animations:^{
actionContainer.frame = CGRectMake(0.0, 0.0, htmlTest.webViewTest.bounds.size.width, htmlTest.webViewTest.bounds.size.height);
shadeView.alpha = 0.75;
} completion:^(BOOL finished) {
if (finished) {
NSLog(@"YAY!");
}
}];
}
else if ([actionContainer superview]) {
//unload portrait view
[UIView animateWithDuration:0.6
delay:0.0f
options:UIViewAnimationCurveEaseOut
animations:^{
actionContainer.frame = CGRectMake(4.0, 480.0, htmlTest.webViewTest.bounds.size.width, htmlTest.webViewTest.bounds.size.height);
// remove selected tabButton highlight
[actionTabBar setSelectedItem:nil];
shadeView.alpha = 0.0;
} completion:^(BOOL finished) {
if (finished) {
// remove subView for superView
[actionContainer removeFromSuperview];
[shadeView removeFromSuperview];
}
}];
}
在代码的第二部分,我有actionContainer,它保存了从屏幕底部动画的webView,然后在按下一个标签按钮时再次向下返回..所有这些都完美正常它只是当你第一次加载webview时,如果它在横向上显示它正确显示。
更新: 我还在webview和actionContainer视图上运行了一个NSLog,因为在加载时这是输出..
2012-07-10 10:46:09.886 SMPrototypeF[2175:907] My htmlTest frame is: {{0, 0}, {320, 367}}
2012-07-10 10:46:11.044 SMPrototypeF[2175:907] My actionContainer frame is: {{0, 480}, {320, 367}}
所以很明显,视图的宽度不正确..