1

我在 ipad xib 中有一个 webview,在两个方向 w 上都可以正常工作。但是如果我在纵向模式下放大,然后在横向 webview 中旋转从右侧获取边距

- (void)viewDidLoad
{
    NSString *urlString=@"http://www.plus.al";
    NSURLRequest *request=[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
    webView.scalesPageToFit = YES;
    [webView loadRequest:request];
}

- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation 
 {
   if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        if (UIInterfaceOrientationIsLandscape(interfaceOrientation))
        {

            webView.frame=CGRectMake(0, 0, 1024, 748);

        }
        if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) 
        {

            webView.frame=CGRectMake(0, 0, 768, 1004);

        }
    else {
        if (UIInterfaceOrientationIsLandscape(interfaceOrientation))
        { 
            webView.frame=CGRectMake(0, 0, 480, 300);    
        }
        if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) 
        {

            webView.frame=CGRectMake(0, 0, 320, 460);
        }
    }
    return YES;
 }

请帮助我。在此先感谢。

4

1 回答 1

0

您需要改用以下代码-

- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation 
{
    return YES;
}


- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        if (UIInterfaceOrientationIsLandscape(interfaceOrientation))
        {
            self.webView.frame=CGRectMake(0, 0, 1024, 748); 
        }
        if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) 
        {
            self.webView.frame=CGRectMake(0, 0, 768, 1004);
        }
        else {
            if (UIInterfaceOrientationIsLandscape(interfaceOrientation))
            { 
                self.webView.frame=CGRectMake(0, 0, 480, 300);    
            }
            if (UIInterfaceOrientationIsPortrait(interfaceOrientation)) 
            {                
                self.webView.frame=CGRectMake(0, 0, 320, 460);
            }
        }
    }
}
于 2012-05-11T06:54:28.727 回答