| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- //
- // ZLAnimationImageView.m
- // ZLAssetsPickerDemo
- //
- //
- #import "DKAnimationImageView.h"
- #import "DKPhotoPickerBrowserPhoto.h"
- #import "UIView+Extension.h"
- #import "UIImageView+WebCache.h"
- #import "DKPhotoPickerCommon.h"
- #import <AssetsLibrary/AssetsLibrary.h>
- @interface DKAnimationImageView ()
- //@property (nonatomic , strong) NSMutableArray *photos;
- //@property (nonatomic , strong) NSDictionary *options;
- @end
- static NSArray *_photos;
- static UIImageView *_imageView;
- static NSDictionary *_options;
- @implementation DKAnimationImageView
- + (NSArray *)photos{
- if (!_photos) {
- _photos = [NSArray array];
- }
- return _photos;
- }
- + (UIImageView *)imageView{
- if (!_imageView) {
- UIImageView *imageView = [[UIImageView alloc] init];
- imageView.contentMode = UIViewContentModeScaleAspectFit;
- imageView.clipsToBounds = YES;
- DKAnimationBaseView *baseView = [DKAnimationBaseView sharedManager];
- [baseView addSubview:imageView];
- _imageView = imageView;
- }
- return _imageView;
- }
- + (instancetype)animationViewWithOptions:(NSDictionary *)options animations:(void (^)())animations completion:(void (^)(DKAnimationBaseView *))completion{
-
- NSAssert([options[UIViewAnimationImages] isKindOfClass:[NSArray class]], @"只能传图片数组!");
-
- _photos = options[UIViewAnimationImages];
- if ([(UIView*)options[UIViewAnimationToView] width] == [(UIView*)options[UIViewAnimationToView] height]) {
- self.imageView.contentMode = UIViewContentModeScaleAspectFill;
- }else{
- self.imageView.contentMode = UIViewContentModeScaleAspectFit;
- }
-
- NSMutableDictionary *ops = [NSMutableDictionary dictionaryWithDictionary:options];
- // 根据索引值来赋值
- NSIndexPath *indexPath = options[UIViewAnimationTypeViewWithIndexPath];
- // 设置图片
- [self setingPhotoImageAtIndex:indexPath.row ];
-
- ops[UIViewAnimationSelfView] = [self imageView];
- _options = ops;
- return [super animationViewWithOptions:ops animations:animations completion:completion];
- }
- + (void)restoreWithOptions:(NSDictionary *)options animation:(void (^)())completion{
- [self setingPhotoImageAtIndex:[[self currentIndexPath] item]];
- [super restoreWithOptions:options animation:completion];
- }
- #pragma make - 设置图片
- + (void) setingPhotoImageAtIndex:(NSInteger)index{
-
- if (!_photos.count) {
- return ;
- }
-
- if (index >= _photos.count) {
- index = _photos.count - 1;
- }
-
- DKPhotoPickerBrowserPhoto *photo = _photos[index];//[self photoWithAtIndex:self.currentPage];
- UIButton *cView = _options[UIViewAnimationToView];
- UIImage *image = nil;
- if (photo.photoImage) {
- image = photo.photoImage;
- }else if (photo.thumbImage){
- image = photo.thumbImage;
- }else if (photo.photoURL){
- [[self imageView] sd_setImageWithURL:photo.photoURL placeholderImage:nil];
- return;
- }
-
- if (!image) {
- if ([cView isKindOfClass:[UIButton class]]) {
- image = cView.imageView.image;
- }else if ([cView isKindOfClass:[UIImageView class]]){
- UIImageView *ig = (UIImageView *)cView;
- image = ig.image;
- }
- }
-
- [[self imageView] setImage:image];
-
-
- }
- @end
|