【问题标题】:UIWebView autosize issue only on iOS 4.3UIWebView 仅在 iOS 4.3 上自动调整大小问题
【发布时间】:2012-10-13 01:58:46
【问题描述】:

我正试图弄清楚如何修复这个仅在 iOS 4.3 上出现的错误。当应用程序启动时,它会显示一个 PDF,该 PDF 已缩放以适合 UIWebView。它表现完美,直到您捏合以放大文档,然后旋转它,留下黑色区域。如果你不捏缩放,它不会离开黑色区域。我不明白为什么这是一个 iOS 4.3 唯一的问题。 问题截图:我一直在尝试解决这个问题,非常感谢您的帮助。谢谢。

.xib 设置的屏幕截图:

我使用的代码是:

.h:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
{
   UIWebView *webView;
}

@property (nonatomic) IBOutlet UIWebView *webView;

@end

.m:

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize webView;

- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    return YES;
    } else {
    return (interfaceOrientation !=
            UIInterfaceOrientationPortraitUpsideDown);
    }
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSString *urlAddress = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"pdf"];

    NSURL *url = [NSURL fileURLWithPath:urlAddress]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

    [webView loadRequest:requestObj];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

@end

【问题讨论】:

    标签: iphone objective-c ios uiview uiwebview


    【解决方案1】:

    我记得过去 UIWebView 和旋转存在一些错误。我特别记得有一些渲染和调整大小的问题。老实说,如果它从 iOS 4.3 开始就有效,那么我认为你甚至不应该费心去尝试解决这个问题——在这一点上,你想出的解决方法很可能会很老套且无关紧要。

    话虽如此,this thread 可能会帮助您解决问题。

    【讨论】:

    • 您提供的链接很有帮助。我想我什至不会费心修复它,因为几乎没有人在 iOS 4.3 上?
    【解决方案2】:

    如果它在 iOS6 中工作,可能是因为 shouldAutorotateToInterfaceOrientation 从未在其中被调用。 iOS6 改变了处理旋转的方式。它碰巧在您的代码中起作用。

    另一种可能的解决方案是使用 webview 的委托等到它被加载然后将其添加到视图中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-06
      • 2011-07-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多