Skip to content

Commit

Permalink
修复BUG,优化功能
Browse files Browse the repository at this point in the history
  • Loading branch information
indulgeIn committed Oct 8, 2018
1 parent a191b27 commit 7acc8c8
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 16 deletions.
5 changes: 4 additions & 1 deletion YBImageBrowser/AuxiliaryView/YBImageBrowserSheetView.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "YBImageBrowserSheetView.h"
#import "YBIBCopywriter.h"
#import "YBIBUtilities.h"
#import "YBImageBrowserTipView.h"

NSString * const kYBImageBrowserSheetActionIdentitySaveToPhotoAlbum = @"kYBImageBrowserSheetActionIdentitySaveToPhotoAlbum";

Expand Down Expand Up @@ -174,8 +175,10 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
if ([self.actions[indexPath.row].identity isEqualToString:kYBImageBrowserSheetActionIdentitySaveToPhotoAlbum]) {
if ([self->_data respondsToSelector:@selector(yb_browserAllowSaveToPhotoAlbum)] && [self->_data respondsToSelector:@selector(yb_browserSaveToPhotoAlbum)]) {
if ([self->_data respondsToSelector:@selector(yb_browserSaveToPhotoAlbum)] && [self->_data respondsToSelector:@selector(yb_browserAllowSaveToPhotoAlbum)] && [self->_data yb_browserAllowSaveToPhotoAlbum]) {
[self->_data yb_browserSaveToPhotoAlbum];
} else {
[YBIBGetNormalWindow() yb_showForkTipView:[YBIBCopywriter shareCopywriter].unableToSave];
}
} else {
self.actions[indexPath.row].action(self->_data);
Expand Down
3 changes: 3 additions & 0 deletions YBImageBrowser/ImageBrowse/YBImageBrowseCellData.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ When the image exceeds this texture size, it will be compressed asynchronously a
/** The default is YES. */
@property (nonatomic, assign) BOOL allowSaveToPhotoAlbum;

/** The default is YES. */
@property (nonatomic, assign) BOOL allowShowSheetView;

/** You can set any data. */
@property (nonatomic, strong, nullable) id extraData;

Expand Down
5 changes: 5 additions & 0 deletions YBImageBrowser/ImageBrowse/YBImageBrowseCellData.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ - (void)initVars {
self->_verticalfillType = YBImageBrowseFillTypeUnknown;
self->_horizontalfillType = YBImageBrowseFillTypeUnknown;
self->_allowSaveToPhotoAlbum = YES;
self->_allowShowSheetView = YES;

self->_isCutting = NO;
}
Expand All @@ -67,6 +68,10 @@ - (CGRect)yb_browserCurrentImageFrameWithImageSize:(CGSize)size {
return [self.class getImageViewFrameWithContainerSize:[self.class getSizeOfCurrentLayoutDirection] imageSize:size fillType:[self getFillTypeWithLayoutDirection:[YBIBLayoutDirectionManager getLayoutDirectionByStatusBar]]];
}

- (BOOL)yb_browserAllowShowSheetView {
return self.allowShowSheetView;
}

- (BOOL)yb_browserAllowSaveToPhotoAlbum {
return self.allowSaveToPhotoAlbum;
}
Expand Down
3 changes: 3 additions & 0 deletions YBImageBrowser/VideoBrowse/YBVideoBrowseCellData.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ NS_ASSUME_NONNULL_BEGIN
/** The default is YES. */
@property (nonatomic, assign) BOOL allowSaveToPhotoAlbum;

/** The default is YES. */
@property (nonatomic, assign) BOOL allowShowSheetView;

/** You can set any data. */
@property (nonatomic, strong, nullable) id extraData;

Expand Down
5 changes: 5 additions & 0 deletions YBImageBrowser/VideoBrowse/YBVideoBrowseCellData.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ - (instancetype)init {
- (void)initVars {
self->_autoPlayCount = 0;
self->_allowSaveToPhotoAlbum = YES;
self->_allowShowSheetView = YES;
self->_dataState = YBVideoBrowseCellDataStateInvalid;
self->_dataDownloadState = YBVideoBrowseCellDataDownloadStateNone;
}
Expand Down Expand Up @@ -68,6 +69,10 @@ - (CGRect)yb_browserCurrentImageFrameWithImageSize:(CGSize)size {
return CGRectMake(x, y, width, height);
}

- (BOOL)yb_browserAllowShowSheetView {
return self.allowShowSheetView;
}

- (BOOL)yb_browserAllowSaveToPhotoAlbum {
return self.allowSaveToPhotoAlbum;
}
Expand Down
26 changes: 14 additions & 12 deletions YBImageBrowser/YBImageBrowser.m
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ - (void)viewDidAppear:(BOOL)animated {
[self addSubViews];

self->_isFirstViewDidAppear = YES;

[self addNotification];
}
}

Expand Down Expand Up @@ -143,6 +145,18 @@ - (void)respondsToLongPress:(UILongPressGestureRecognizer *)sender {
}
}

#pragma mark - notification

- (void)addNotification {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(adjustStatusBar) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
}

- (void)adjustStatusBar {
if ([UIApplication sharedApplication].statusBarFrame.size.height > YBIB_HEIGHT_STATUSBAR) {
self.view.frame = CGRectMake(0, 0, self->_containerSize.width, self->_containerSize.height);
}
}

#pragma mark - private

- (void)addSubViews {
Expand Down Expand Up @@ -176,18 +190,6 @@ - (void)updateLayoutOfSubViewsWithLayoutDirection:(YBImageBrowserLayoutDirection
}];
}

- (BOOL)isControllerPreferredForStatusBar {
static BOOL isControllerPreferred = NO;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
NSString *bundlePath = [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"];
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithContentsOfFile:bundlePath];
id value = dict[@"UIViewControllerBasedStatusBarAppearance"];
isControllerPreferred = value ? [value boolValue] : YES;
});
return isControllerPreferred;
}

#pragma mark - public

- (void)setDataSource:(id<YBImageBrowserDataSource>)dataSource {
Expand Down
4 changes: 1 addition & 3 deletions YBImageBrowserDemo/UseCase/MainViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -139,16 +139,14 @@ - (NSUInteger)yb_numberOfCellForImageBrowserView:(YBImageBrowserView *)imageBrow
YBVideoBrowseCellData *data = [YBVideoBrowseCellData new];
data.phAsset = asset;
data.sourceObject = [self sourceObjAtIdx:index];
// data.allowSaveToPhotoAlbum = NO;


return data;
} else if (asset.mediaType == PHAssetMediaTypeImage) {

// Type 2 : 系统相册的图片 / Image of system album
YBImageBrowseCellData *data = [YBImageBrowseCellData new];
data.phAsset = asset;
data.sourceObject = [self sourceObjAtIdx:index];
// data.allowSaveToPhotoAlbum = NO;

return data;
}
Expand Down

0 comments on commit 7acc8c8

Please sign in to comment.