ibireme / YYWebImage

Asynchronous image loading framework.
MIT License
3.56k stars 615 forks source link

yy_setImageWithURL的transform block里面修改size和圆角都不生效 #158

Open Steven-Yung opened 7 years ago

Steven-Yung commented 7 years ago

用户头像需要调整大小和设置圆角,我用了这个方法

[self.userAvatar yy_setImageWithURL:[NSURL URLWithString:model.portrait]
                            placeholder:placeholder
                                options:YYWebImageOptionIgnoreFailedURL
                                manager:[YYWebImageManager sharedManager]
                               progress:^(NSInteger receivedSize, NSInteger expectedSize) {

    } transform:^UIImage * _Nullable(UIImage * _Nonnull image, NSURL * _Nonnull url) {
        image = [image yy_imageByResizeToSize:placeholder.size contentMode:UIViewContentModeCenter];
        [image yy_imageByRoundCornerRadius:5.0];
        return image;
    } completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {

    }];

结果图片还是原来的大小,并且圆角也没有生效,是不是哪里不对?

GhostZephyr commented 7 years ago

用法问题 我这是好的 你调试看看

0xxxD commented 7 years ago

试试 UIViewContentModeScaleToFill

[cell.avatarButton yy_setImageWithURL:[NSURL URLWithString:photo.avatarSmallURL]
                                 forState:UIControlStateNormal
                              placeholder:nil
                                  options:YYWebImageOptionProgressiveBlur | YYWebImageOptionShowNetworkActivity | YYWebImageOptionSetImageWithFadeAnimation
                                  manager:nil
                                 progress:^(NSInteger receivedSize, NSInteger expectedSize) {

                                  }
                                transform:^UIImage * _Nullable(UIImage * _Nonnull image, NSURL * _Nonnull url) {
                                    @StrongObj(cell);

                                    image = [image yy_imageByResizeToSize:cellStrong.avatarButton.frame.size contentMode:UIViewContentModeScaleToFill];
                                    return [image yy_imageByRoundCornerRadius:cellStrong.avatarButton.frame.size.width/2];
                                }
                               completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {

                               }];
Homin818 commented 7 years ago

是缓存问题吧,试试清空缓存

Homin818 commented 7 years ago

https://github.com/ibireme/YYWebImage/pull/190

XavierLost commented 6 years ago

YYWebImageOptionIgnoreDiskCache 把这个用上就不会