ios - iOS4 中的 UIWebView ScalesToFit 和 AspectFit

标签 ios ios5 ios4 uiwebview

我一直在尝试在 UIWebView 中显示一些来自网络的图像。我一直在做的是直接在 URL 上使用 loadRequest: 方法,使用 ScalesToFit = YES 和 AspectFit 模式来使其适合 WebView 框架。这在 iOS5 上工作正常,但在 iOS4 上却不行。在 iOS4 中,图像显示为缩小。

Here's a screenshot of it in iOS5

And what I get in iOS4

据我了解,iOS5 带有集成的 ScrollView,而 iOS4 及更早版本则没有。是因为这个吗?如果是的话,我怎样才能完成我想做的事情?我尝试将 UIWebView 放入 UIScrollView 并设置 scalesToFit 和 AspectView 设置,但仍然得到相同的结果。

最佳答案

为什么不先下载图片呢?我编写这个函数就是为了做到这一点:

-(void)loadImageFromURL:(NSString*)url{
    [delegate didBeginLoadingFromURL:url];

    NSData * imageData = [[NSData dataWithContentsOfURL:[NSURL URLWithString:url]] retain];
    UIImage *image = [[UIImage alloc] initWithData:imageData];  

    if (delegate && [delegate respondsToSelector:@selector(didRecieveImage:FromURL:)]) { //Make sure the delegage still exists and what not ;)
             [delegate didRecieveImage:image FromURL:url];
    }

    [imageData release];
    [image release];

关于ios - iOS4 中的 UIWebView ScalesToFit 和 AspectFit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9797616/

相关文章:

iphone - 访问歌曲上的 BPM 字段(MPMediaItemPropertyBeatsPerMinute 不起作用)

ios - 谷歌建议类似ios中的功能

ios - 如何切换IOS相机

iphone - 圆弧错误 : receiver type for instance message does not declare a method with selector

ios - Facebook iOS SDK,针对 FBSession 的异常,*** 断言失败 -[FBSession 关闭]

iphone - TBXML 将复杂的 xml 解析为数组

ios - xcode 5.0.1 中 iphone 4 的启动屏幕没有变化

SecTransformRef 的 iOS 等效项?

c++ - 使用 AVFoundation 为 iPhone 添加覆盖/操作?

ios - 如何将 NSArray 参数传递给完成 block