uicollectionview中cell在重用时候cell的什么属性会随着滚动改变
1个回答
2016-07-17 · 做真实的自己 用良心做教育
千锋教育
千锋教育专注HTML5大前端、JavaEE、Python、人工智能、UI&UE、云计算、全栈软件测试、大数据、物联网+嵌入式、Unity游戏开发、网络安全、互联网营销、Go语言等培训教育。
向TA提问
关注
展开全部
这里是自定义的 UICollectionViewCell 的实现。
#import "MyCollectionViewCell.h"
#import <QuartzCore/QuartzCore.h>
#import <AVFoundation/AVFoundation.h>
@interface MyCollectionViewCell ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end
@implementation MyCollectionViewCell
@synthesize urlString = _urlString;
+ (void)loadAsyncImageFromURL:(NSString *)urlString withCallback:(void (^)(UIImage *))callback {
NSURL *url = [NSURL URLWithString:urlString];
dispatch_queue_t downloadQueue = dispatch_queue_create("com.example.downloadqueue", NULL);
dispatch_async(downloadQueue, ^{
NSData * imageData = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:imageData];
dispatch_async(dispatch_get_main_queue(), ^{
callback(image);
});
});
}
-(void) fadeInView:(UIView *)view WithSecondDuration:(double)duration {
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
animation.beginTime = 0;
animation.duration = duration;
animation.fromValue = [NSNumber numberWithFloat:0.0f];
animation.toValue = [NSNumber numberWithFloat:1.0f];
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeBoth;
animation.additive = NO;
[view.layer addAnimation:animation forKey:@"opacityIN"];
}
- (void) setUrlString:(NSString *)urlString {
_urlString = urlString;
self.imageView.image = nil;
self.imageView.layer.opacity = 0;
if (urlString) {
[MyCollectionViewCell loadAsyncImageFromURL:urlString withCallback:^(UIImage *image) {
self.imageView.image = image;
[self fadeInView:self.imageView WithSecondDuration:.25];
}];
}
}
#import "MyCollectionViewCell.h"
#import <QuartzCore/QuartzCore.h>
#import <AVFoundation/AVFoundation.h>
@interface MyCollectionViewCell ()
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
@end
@implementation MyCollectionViewCell
@synthesize urlString = _urlString;
+ (void)loadAsyncImageFromURL:(NSString *)urlString withCallback:(void (^)(UIImage *))callback {
NSURL *url = [NSURL URLWithString:urlString];
dispatch_queue_t downloadQueue = dispatch_queue_create("com.example.downloadqueue", NULL);
dispatch_async(downloadQueue, ^{
NSData * imageData = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:imageData];
dispatch_async(dispatch_get_main_queue(), ^{
callback(image);
});
});
}
-(void) fadeInView:(UIView *)view WithSecondDuration:(double)duration {
CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"opacity"];
animation.beginTime = 0;
animation.duration = duration;
animation.fromValue = [NSNumber numberWithFloat:0.0f];
animation.toValue = [NSNumber numberWithFloat:1.0f];
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeBoth;
animation.additive = NO;
[view.layer addAnimation:animation forKey:@"opacityIN"];
}
- (void) setUrlString:(NSString *)urlString {
_urlString = urlString;
self.imageView.image = nil;
self.imageView.layer.opacity = 0;
if (urlString) {
[MyCollectionViewCell loadAsyncImageFromURL:urlString withCallback:^(UIImage *image) {
self.imageView.image = image;
[self fadeInView:self.imageView WithSecondDuration:.25];
}];
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询