【问题标题】:UIWebView ScalesToFit and AspectFit in iOS4iOS4 中的 UIWebView ScalesToFit 和 AspectFit
【发布时间】:2012-03-21 01:54:00
【问题描述】:

我一直在尝试在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 设置,但我仍然得到相同的结果。

【问题讨论】:

    标签: ios ios5 ios4 uiwebview


    【解决方案1】:

    为什么不先下载图片呢?我为此编写了这个函数:

    -(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];
    

    }

    【讨论】:

    • 感谢您的回答和分享您的方法:) 但我正在尝试使用 UIWebView,因为它集成了缩放和平移功能,因为大多数图像都大于框架。
    • 您可以在 UIScrollView 中放置一个 UIImageView 以获得平移和缩放功能,这是正确的方法。
    猜你喜欢
    • 2014-08-04
    • 2011-03-19
    • 2011-03-01
    • 2011-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-09
    • 1970-01-01
    相关资源
    最近更新 更多