@@ -66,7 +66,7 @@ - (void)configSubviews {
6666
6767- (void )setModel : (TZAssetModel *)model {
6868 [super setModel: model];
69- _previewView.asset = model. asset ;
69+ _previewView.model = model;
7070}
7171
7272- (void )recoverSubviews {
@@ -133,20 +133,17 @@ - (instancetype)initWithFrame:(CGRect)frame {
133133 _imageView.contentMode = UIViewContentModeScaleAspectFill;
134134 _imageView.clipsToBounds = YES ;
135135 [_imageContainerView addSubview: _imageView];
136-
137- _iCloudErrorView = [[UIView alloc ] initWithFrame: CGRectMake (0 , [TZCommonTools tz_isIPhoneX ] ? 88 : 64 , self .tz_width, 28 )];
138- UIImageView *icloud = [[UIImageView alloc ] init ];
139- icloud.image = [UIImage tz_imageNamedFromMyBundle: @" iCloudError" ];
140- icloud.frame = CGRectMake (10 , 0 , 28 , 28 );
141- [_iCloudErrorView addSubview: icloud];
142- UILabel *label = [[UILabel alloc ] init ];
143- label.frame = CGRectMake (40 , 0 , self.tz_width - 50 , 28 );
144- label.font = [UIFont systemFontOfSize: 10 ];
145- label.textColor = [UIColor whiteColor ];
146- label.text = [NSBundle tz_localizedStringForKey: @" iCloud sync failed" ];
147- [_iCloudErrorView addSubview: label];
148- [self addSubview: _iCloudErrorView];
149- _iCloudErrorView.hidden = YES ;
136+
137+ _iCloudErrorIcon = [[UIImageView alloc ] init ];
138+ _iCloudErrorIcon.image = [UIImage tz_imageNamedFromMyBundle: @" iCloudError" ];
139+ _iCloudErrorIcon.hidden = YES ;
140+ [self addSubview: _iCloudErrorIcon];
141+ _iCloudErrorLabel = [[UILabel alloc ] init ];
142+ _iCloudErrorLabel.font = [UIFont systemFontOfSize: 10 ];
143+ _iCloudErrorLabel.textColor = [UIColor whiteColor ];
144+ _iCloudErrorLabel.text = [NSBundle tz_localizedStringForKey: @" iCloud sync failed" ];
145+ _iCloudErrorLabel.hidden = YES ;
146+ [self addSubview: _iCloudErrorLabel];
150147
151148 UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc ] initWithTarget: self action: @selector (singleTap: )];
152149 [self addGestureRecognizer: tap1];
@@ -173,12 +170,15 @@ - (void)setModel:(TZAssetModel *)model {
173170 if (model.type == TZAssetModelMediaTypePhotoGif) {
174171 // 先显示缩略图
175172 [[TZImageManager manager ] getPhotoWithAsset: model.asset completion: ^(UIImage *photo, NSDictionary *info, BOOL isDegraded) {
176- if (!photo && [info[PHImageResultIsInCloudKey] boolValue ]) {
177- self.iCloudErrorView .hidden = NO ;
178- } else {
179- self.iCloudErrorView .hidden = YES ;
173+ BOOL iCloudSyncFailed = !photo && [info[PHImageResultIsInCloudKey] boolValue ];
174+ self.iCloudErrorLabel .hidden = !iCloudSyncFailed;
175+ self.iCloudErrorIcon .hidden = !iCloudSyncFailed;
176+ if (self.iCloudSyncFailedHandle ) {
177+ self.iCloudSyncFailedHandle (model.asset , iCloudSyncFailed);
178+ }
179+ if (photo) {
180+ self.imageView .image = photo;
180181 }
181- self.imageView .image = photo;
182182 [self resizeSubviews ];
183183 if (self.isRequestingGIF ) {
184184 return ;
@@ -223,13 +223,16 @@ - (void)setAsset:(PHAsset *)asset {
223223
224224 _asset = asset;
225225 self.imageRequestID = [[TZImageManager manager ] getPhotoWithAsset: asset completion: ^(UIImage *photo, NSDictionary *info, BOOL isDegraded) {
226+ BOOL iCloudSyncFailed = !photo && [info[PHImageResultIsInCloudKey] boolValue ];
227+ self.iCloudErrorLabel .hidden = !iCloudSyncFailed;
228+ self.iCloudErrorIcon .hidden = !iCloudSyncFailed;
229+ if (self.iCloudSyncFailedHandle ) {
230+ self.iCloudSyncFailedHandle (asset, iCloudSyncFailed);
231+ }
226232 if (![asset isEqual: self ->_asset]) return ;
227- if (!photo && [info[PHImageResultIsInCloudKey] boolValue ]) {
228- self.iCloudErrorView .hidden = NO ;
229- } else {
230- self.iCloudErrorView .hidden = YES ;
233+ if (photo) {
234+ self.imageView .image = photo;
231235 }
232- self.imageView .image = photo;
233236 [self resizeSubviews ];
234237 if (self.imageView .tz_height && self.allowCrop ) {
235238 CGFloat scale = MAX (self.cropRect .size .width / self.imageView .tz_width , self.cropRect .size .height / self.imageView .tz_height );
@@ -240,7 +243,7 @@ - (void)setAsset:(PHAsset *)asset {
240243 [self .scrollView setZoomScale: scale animated: YES ];
241244 }
242245 }
243-
246+
244247 self->_progressView .hidden = YES ;
245248 if (self.imageProgressUpdateBlock ) {
246249 self.imageProgressUpdateBlock (1 );
@@ -337,8 +340,9 @@ - (void)layoutSubviews {
337340 CGFloat progressX = (self.tz_width - progressWH) / 2 ;
338341 CGFloat progressY = (self.tz_height - progressWH) / 2 ;
339342 _progressView.frame = CGRectMake (progressX, progressY, progressWH, progressWH);
340-
341343 [self recoverSubviews ];
344+ _iCloudErrorIcon.frame = CGRectMake (20 , [TZCommonTools tz_isIPhoneX ] ? 88 + 10 : 64 + 10 , 28 , 28 );
345+ _iCloudErrorLabel.frame = CGRectMake (53 , [TZCommonTools tz_isIPhoneX ] ? 88 + 10 : 64 + 10 , self.tz_width - 63 , 28 );
342346}
343347
344348#pragma mark - UITapGestureRecognizer Event
@@ -395,6 +399,14 @@ @implementation TZVideoPreviewCell
395399
396400- (void )configSubviews {
397401 [[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (appWillResignActiveNotification ) name: UIApplicationWillResignActiveNotification object: nil ];
402+ _iCloudErrorIcon = [[UIImageView alloc ] init ];
403+ _iCloudErrorIcon.image = [UIImage tz_imageNamedFromMyBundle: @" iCloudError" ];
404+ _iCloudErrorIcon.hidden = YES ;
405+ _iCloudErrorLabel = [[UILabel alloc ] init ];
406+ _iCloudErrorLabel.font = [UIFont systemFontOfSize: 10 ];
407+ _iCloudErrorLabel.textColor = [UIColor whiteColor ];
408+ _iCloudErrorLabel.text = [NSBundle tz_localizedStringForKey: @" iCloud sync failed" ];
409+ _iCloudErrorLabel.hidden = YES ;
398410}
399411
400412- (void )configPlayButton {
@@ -406,6 +418,8 @@ - (void)configPlayButton {
406418 [_playButton setImage: [UIImage tz_imageNamedFromMyBundle: @" MMVideoPreviewPlayHL" ] forState: UIControlStateHighlighted];
407419 [_playButton addTarget: self action: @selector (playButtonClick ) forControlEvents: UIControlEventTouchUpInside];
408420 [self addSubview: _playButton];
421+ [self addSubview: _iCloudErrorIcon];
422+ [self addSubview: _iCloudErrorLabel];
409423}
410424
411425- (void )setModel : (TZAssetModel *)model {
@@ -428,10 +442,24 @@ - (void)configMoviePlayer {
428442
429443 if (self.model && self.model .asset ) {
430444 [[TZImageManager manager ] getPhotoWithAsset: self .model.asset completion: ^(UIImage *photo, NSDictionary *info, BOOL isDegraded) {
431- self.cover = photo;
445+ BOOL iCloudSyncFailed = !photo && [info[PHImageResultIsInCloudKey] boolValue ];
446+ self.iCloudErrorLabel .hidden = !iCloudSyncFailed;
447+ self.iCloudErrorIcon .hidden = !iCloudSyncFailed;
448+ if (self.iCloudSyncFailedHandle ) {
449+ self.iCloudSyncFailedHandle (self.model .asset , iCloudSyncFailed);
450+ }
451+ if (photo) {
452+ self.cover = photo;
453+ }
432454 }];
433455 [[TZImageManager manager ] getVideoWithAsset: self .model.asset completion: ^(AVPlayerItem *playerItem, NSDictionary *info) {
434456 dispatch_async (dispatch_get_main_queue (), ^{
457+ BOOL iCloudSyncFailed = !playerItem && [info[PHImageResultIsInCloudKey] boolValue ];
458+ self.iCloudErrorLabel .hidden = !iCloudSyncFailed;
459+ self.iCloudErrorIcon .hidden = !iCloudSyncFailed;
460+ if (self.iCloudSyncFailedHandle ) {
461+ self.iCloudSyncFailedHandle (self.model .asset , iCloudSyncFailed);
462+ }
435463 [self configPlayerWithItem: playerItem];
436464 });
437465 }];
@@ -455,6 +483,8 @@ - (void)layoutSubviews {
455483 [super layoutSubviews ];
456484 _playerLayer.frame = self.bounds ;
457485 _playButton.frame = CGRectMake (0 , 64 , self.tz_width , self.tz_height - 64 - 44 );
486+ _iCloudErrorIcon.frame = CGRectMake (20 , [TZCommonTools tz_isIPhoneX ] ? 88 + 10 : 64 + 10 , 28 , 28 );
487+ _iCloudErrorLabel.frame = CGRectMake (53 , [TZCommonTools tz_isIPhoneX ] ? 88 + 10 : 64 + 10 , self.tz_width - 63 , 28 );
458488}
459489
460490- (void )photoPreviewCollectionViewDidScroll {
0 commit comments