- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的项目中,我需要使用AsyncImageView
来加载图像。我还希望这些图像是圆形的。图像主要出现在表格 View 中,因此我无法在 AsyncImageView 层上使用圆角,因为这会对应用程序的性能产生非常非常负面的影响。
所以我决定创建一个 AsyncImageView
的子类(因为我项目中的其他 View 需要原始的非圆形 AsyncImageView),名为 RoundedAsyncImageView
,其中我只实现了 drawRect
方法,如下所示:
- (void)drawRect:(CGRect)rect
{
CGContextRef ctx = UIGraphicsGetCurrentContext();
CGContextSaveGState(ctx);
CGPathRef clippath = [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:17].CGPath;
CGContextAddPath(ctx, clippath);
CGContextClip(ctx);
[self.image drawInRect:rect];
CGContextRestoreGState(ctx);
}
我有 xib 用于应该出现这个圆形图像的单元格,是用 IB 创建的。所以我只是将 UIImageView
元素的自定义类更改为 RoundedAsyncImageView
并将 ImageView 的 IBOutlet
更改为 RoundedAsyncImageView
>。现在的问题是 drawRect
没有被调用。有什么想法吗?
编辑:我读到,UIImageView
子类不调用drawRect,并且我应该简单地在常规UIView
子类中绘制图像。问题是,我实际上不能那样做,因为我需要 AsyncImageView
的异步加载图像功能。有什么办法吗?
最佳答案
UIImageView
上的 DrawRect
方法与 UIView
略有不同
The view still has a CALayer, but the layer doesn’t allocate a backing store. Instead it uses a CGImageRef as its contents and the render server will draw that image’s bits into the frame buffer.
In this case, there’s no drawing going on. We’re simply passing bitmap data in form of an image to the UIImageView.
引用这篇文章Getting Pixels onto the Screen ,根据我的经验,这就是为什么你的 imageView 剪辑方法无法工作。
这是我的解决方案:
AsyncImageView
的子类,而是创建 UIView
的子类。AsyncImageView
,这意味着您的子类成为 AsyncImageView
的包装 View 。关于ios - 未在 AsyncImageView 的子类中调用 drawRect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21477739/
使用 asyncImageView 加载带有 url 的图像集时遇到崩溃问题。我收到的错误是 -[__NSCFString isFileURL]: unrecognized selector sent
我刚刚更新到 Xcode 7 和 Swift 2.0,当然它在我的应用程序中引起了一些问题。我已经解决了很多问题,但我正在努力解决这个问题。 在我的 TableView 中,我正在加载来自 Parse
在我的项目中,我需要使用AsyncImageView 来加载图像。我还希望这些图像是圆形的。图像主要出现在表格 View 中,因此我无法在 AsyncImageView 层上使用圆角,因为这会对应用程
在我的应用程序中,我使用 AsyncImageView 库异步加载和显示图像,它还声称它缓存了图像。 图书馆可以在这里找到:https://github.com/nicklockwood/AsyncI
我使用 AsyncImageView 从 url 加载图像。但是图像没有加载到 ImageView 宽度。下面是我的代码。 { AsyncImageView *asyImage; as
//UITableView NSString *data_image; data_image = [[message_array objectAtIndex:indexPath.row] val
我开发了一个使用 Asyncimageview 和 iCarousel 的应用程序。但我的问题是,当我尝试从 url 加载图像时,我的 iCarousel 的每个 View 中仅加载事件指示器,而没有
我是一名优秀的程序员,十分优秀!