使用webview进行ipad定位问题并放大

时间:2012-05-02 05:08:23

标签: iphone

我在ipad xib中有一个webview,它在两个方向都很好。 但如果我在纵向模式下放大,然后在横向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;
 }
请帮帮我。谢谢。

1 个答案:

答案 0 :(得分: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);
            }
        }
    }
}