我以编程方式创建了一个 WebView。并在方向改变时改变它的大小。但是当我改变那个 webview 的大小时,它会改变但并不顺利。我怎样才能让它顺利改变大小。
这是我的代码。
- (void)viewDidLoad
{
[super viewDidLoad];
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 44, self.view.frame.size.width, self.view.frame.size.height-44)]; //Change self.view.bounds to a smaller CGRect if you don't want it to take up the whole screen
NSURL * urlStr = [NSURL URLWithString:@"https://www.google.co.in/"];
[webView loadRequest:[NSURLRequest requestWithURL:urlStr]];
[self.view addSubview:webView];
}
-(void)orientationChanged {
UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;
CGRect screenBounds = [[UIScreen mainScreen] bounds];
if(orientation == UIInterfaceOrientationLandscapeLeft)
{
if (screenBounds.size.height == 568)
{
webView.frame = CGRectMake(0, 44, 568, 230);
}
else
{
webView.frame = CGRectMake(0, 44, 480, 230);
}
}
else if(orientation == UIInterfaceOrientationLandscapeRight)
{
if (screenBounds.size.height == 568)
{
webView.frame = CGRectMake(0, 44,568, 230);
}
else
{
webView.frame = CGRectMake(0, 44, 480, 230);
}
}
else if(orientation == UIInterfaceOrientationPortrait)
{
//do change in design when ios change
if (screenBounds.size.height == 568)
{
webView.frame = CGRectMake(0, 44, 320, 524);
}
else
{
webView.frame = CGRectMake(0, 44, 320, 400);
}
}
else if(orientation == UIInterfaceOrientationPortraitUpsideDown)
{
//Do what you want in Portrait Upside Down
}
}