objective-c - How to adjust the size of the displayed image when loading a network image from SDWebImage
滿天的星座
滿天的星座 2017-05-02 09:29:09
0
1
865

As shown in the picture: This is a screenshot of a 6s mobile phone. I put him in a UIImageView with a width = mobile phone screen width and a height of 210. This picture is obtained through network loading. Here I use SDWebImage. Now I want the image to look better, my idea is to crop this image. The problem is that the network request here is asynchronous. I don't know where to handle it.

My core problem is that I don’t know where to crop the web image loaded based on SDWebImage after it is loaded.

I want the online pictures to be displayed as follows: I already have the code for the cropping part. I just don't know where to modify it.

滿天的星座
滿天的星座

reply all(1)
淡淡烟草味

Use the download option SDWebImageAvoidAutoSetImage, 下载完成后在后台剪裁,然后在主线程设置image并调用刷新。
可以给 UIImageViewWrite a category for easy calling.

UIImageView *imageView;

    __weak __typeof(&*imageView) weakImageView = imageView;
    [imageView sd_setImageWithURL:url
                 placeholderImage:placeholder
                          options:SDWebImageAvoidAutoSetImage // 下载完成后不要自动设置image
                        completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
            image = [image croppedImage:...]; // 后台线程剪裁图片

            dispatch_async(dispatch_get_main_queue(), ^{
                __typeof(&*weakImageView) strongImageView = weakImageView;
                if (strongImageView) {
                    strongImageView.image = image;
                    [strongImageView setNeedsLayout];
                }
            });
        });
    }];
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template