Skip to content

Commit

Permalink
[fix] fixed #225
Browse files Browse the repository at this point in the history
  • Loading branch information
indulgeIn committed Sep 26, 2019
1 parent 04bf9b3 commit 3de11a3
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Video/YBIBVideoData.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ typedef void (^YBIBVideoSingleTouchBlock)(YBIBVideoData *videoData);
/// 预览图/缩约图,若 projectiveView 存在且是 UIImageView 类型将会自动获取缩约图
@property (nonatomic, strong, nullable) UIImage *thumbImage;

/// 是否允许保存到相册
@property (nonatomic, assign) BOOL allowSaveToPhotoAlbum;

/// 自动播放次数,默认为 0,NSUIntegerMax 表示无限次
@property (nonatomic, assign) NSUInteger autoPlayCount;

Expand Down
5 changes: 5 additions & 0 deletions Video/YBIBVideoData.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ - (void)initValue {
_repeatPlayCount = 0;
_autoPlayCount = 0;
_shouldHideForkButton = NO;
_allowSaveToPhotoAlbum = YES;
}

#pragma mark - load data
Expand Down Expand Up @@ -161,6 +162,10 @@ - (void)yb_preload {
}
}

- (BOOL)yb_allowSaveToPhotoAlbum {
return self.allowSaveToPhotoAlbum;
}

- (void)yb_saveToPhotoAlbum {
void(^unableToSave)(void) = ^(){
[self.yb_auxiliaryViewHandler() yb_showIncorrectToastWithContainer:self.yb_containerView text:[YBIBCopywriter sharedCopywriter].unableToSave];
Expand Down
2 changes: 1 addition & 1 deletion YBImageBrowser/Base/YBIBContainerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
for (UIView *subView in self.subviews.reverseObjectEnumerator) {
CGPoint subPoint = [self convertPoint:point toView:subView];
UIView *view = [subView hitTest:subPoint withEvent:event];
if (view) return view;
if (view && !view.isHidden && view.alpha > 0 && view.userInteractionEnabled) return view;
}
return nil;
}
Expand Down
3 changes: 3 additions & 0 deletions YBImageBrowser/Image/YBIBImageData.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ typedef void (^YBIBImageScrollViewStatusBlock)(YBIBImageData *imageData, UIScrol
/// 预览图/缩约图 URL,缓存中未找到则忽略(若 projectiveView 存在且是 UIImageView 类型将会自动获取缩约图)
@property (nonatomic, copy, nullable) NSURL *thumbURL;

/// 是否允许保存到相册
@property (nonatomic, assign) BOOL allowSaveToPhotoAlbum;

/// 根据图片信息判断是否需要预解码
@property (nonatomic, copy, nullable) YBIBPreDecodeDecisionBlock preDecodeDecision;

Expand Down
5 changes: 5 additions & 0 deletions YBImageBrowser/Image/YBIBImageData.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ - (void)initValue {
_freezing = NO;
_cuttingSentinel = [YBIBSentinel new];
_interactionProfile = [YBIBInteractionProfile new];
_allowSaveToPhotoAlbum = YES;
}

#pragma mark - load data
Expand Down Expand Up @@ -567,6 +568,10 @@ - (void)yb_preload {
}
}

- (BOOL)yb_allowSaveToPhotoAlbum {
return self.allowSaveToPhotoAlbum;
}

- (void)yb_saveToPhotoAlbum {
void(^saveData)(NSData *) = ^(NSData * _Nonnull data){
[[ALAssetsLibrary new] writeImageDataToSavedPhotosAlbum:data metadata:nil completionBlock:^(NSURL *assetURL, NSError *error) {
Expand Down
7 changes: 6 additions & 1 deletion YBImageBrowser/Protocol/YBIBDataProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,15 @@ NS_ASSUME_NONNULL_BEGIN
- (void)yb_preload;

/**
保存到相册,不实现就表示不支持这个功能
保存到相册
*/
- (void)yb_saveToPhotoAlbum;

/**
是否允许保存到相册
*/
- (BOOL)yb_allowSaveToPhotoAlbum;

@end

NS_ASSUME_NONNULL_END
15 changes: 11 additions & 4 deletions YBImageBrowser/ToolView/YBIBToolViewHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ - (void)yb_containerViewIsReadied {

- (void)yb_pageChanged {
if (self.topView.operationType == YBIBTopViewOperationTypeSave) {
self.topView.operationButton.hidden = ![self.yb_currentData() respondsToSelector:@selector(yb_saveToPhotoAlbum)];
self.topView.operationButton.hidden = [self currentDataShouldHideSaveButton];
}
[self.topView setPage:self.yb_currentPage() totalPage:self.yb_totalPage()];
}
Expand All @@ -58,6 +58,13 @@ - (void)yb_orientationChangeAnimationWithExpectOrientation:(UIDeviceOrientation)

#pragma mark - private

- (BOOL)currentDataShouldHideSaveButton {
id<YBIBDataProtocol> data = self.yb_currentData();
BOOL allow = [data respondsToSelector:@selector(yb_allowSaveToPhotoAlbum)] && [data yb_allowSaveToPhotoAlbum];
BOOL can = [data respondsToSelector:@selector(yb_saveToPhotoAlbum)];
return !(allow && can);
}

- (void)layoutWithExpectOrientation:(UIDeviceOrientation)orientation {
CGSize containerSize = self.yb_containerSize(orientation);
UIEdgeInsets padding = YBIBPaddingByBrowserOrientation(orientation);
Expand All @@ -66,12 +73,12 @@ - (void)layoutWithExpectOrientation:(UIDeviceOrientation)orientation {
}

- (void)showSheetView {
if ([self.yb_currentData() respondsToSelector:@selector(yb_saveToPhotoAlbum)]) {
if ([self currentDataShouldHideSaveButton]) {
[self.sheetView.actions removeObject:self.saveAction];
} else {
if (![self.sheetView.actions containsObject:self.saveAction]) {
[self.sheetView.actions addObject:self.saveAction];
}
} else {
[self.sheetView.actions removeObject:self.saveAction];
}
[self.sheetView showToView:self.yb_containerView orientation:self.yb_currentOrientation()];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ - (void)selectedIndex:(NSInteger)index {
YBImageBrowser *browser = [YBImageBrowser new];
browser.dataSourceArray = datas;
browser.currentPage = index;
browser.defaultToolViewHandler.topView.operationType = YBIBTopViewOperationTypeSave;
[browser show];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ - (void)selectedIndex:(NSInteger)index {
YBImageBrowser *browser = [YBImageBrowser new];
browser.dataSourceArray = datas;
browser.currentPage = index;
// 只有一个保存操作的时候,可以直接右上角显示保存按钮
browser.defaultToolViewHandler.topView.operationType = YBIBTopViewOperationTypeSave;
[browser show];
}

Expand Down

0 comments on commit 3de11a3

Please sign in to comment.