From c04a904adf3bf3a0582d0d95c6ffcd708fc7bf1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E6=B3=A2?= <1106355439@qq.com> Date: Wed, 24 Apr 2019 15:24:34 +0800 Subject: [PATCH] 2.2.0 --- Pods/Pods.xcodeproj/project.pbxproj | 20 +- YBImageBrowser.podspec | 2 +- .../YBImageBrowserProgressView.m | 10 +- .../AuxiliaryView/YBImageBrowserSheetView.m | 26 +-- .../AuxiliaryView/YBImageBrowserTipView.m | 8 +- .../AuxiliaryView/YBImageBrowserToolBar.m | 24 +-- YBImageBrowser/Base/YBImageBrowserView.m | 60 +++--- YBImageBrowser/Helper/YBIBTransitionManager.m | 93 +++++---- YBImageBrowser/Helper/YBIBUtilities.h | 6 +- YBImageBrowser/Helper/YBIBUtilities.m | 24 ++- .../ImageBrowse/YBImageBrowseCell.m | 102 +++++----- .../ImageBrowse/YBImageBrowseCellData.h | 2 +- .../ImageBrowse/YBImageBrowseCellData.m | 28 +-- .../VideoBrowse/YBVideoBrowseActionBar.m | 11 +- .../VideoBrowse/YBVideoBrowseCell.m | 185 +++++++++--------- .../VideoBrowse/YBVideoBrowseCellData.m | 18 +- YBImageBrowser/YBImageBrowser.h | 5 +- YBImageBrowser/YBImageBrowser.m | 84 ++++---- YBImageBrowserDemo.xcodeproj/project.pbxproj | 6 +- .../UseCase/MainViewController.m | 2 +- 20 files changed, 389 insertions(+), 327 deletions(-) diff --git a/Pods/Pods.xcodeproj/project.pbxproj b/Pods/Pods.xcodeproj/project.pbxproj index 90ada8e..068f986 100644 --- a/Pods/Pods.xcodeproj/project.pbxproj +++ b/Pods/Pods.xcodeproj/project.pbxproj @@ -240,13 +240,13 @@ 87D9C7E56F16F61216D8138F736EF305 /* NSData+ImageContentType.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = "NSData+ImageContentType.h"; path = "SDWebImage/NSData+ImageContentType.h"; sourceTree = ""; }; 8881207D3135C02226B14E94C8A5F15E /* UIImageView+WebCache.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = "UIImageView+WebCache.h"; path = "SDWebImage/UIImageView+WebCache.h"; sourceTree = ""; }; 88FD326255010A4B68F88C5FFABC1E6B /* SDImageLoader.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = SDImageLoader.h; path = SDWebImage/SDImageLoader.h; sourceTree = ""; }; - 8942AB1BD931C81624FC00C21D121415 /* SDWebImage.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; name = SDWebImage.framework; path = SDWebImage.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 8942AB1BD931C81624FC00C21D121415 /* SDWebImage.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SDWebImage.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 8B8AB4D0BBFB2485BEB6F0092A8EFAE7 /* YYImageCoder.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = YYImageCoder.m; path = YYImage/YYImageCoder.m; sourceTree = ""; }; 8D3D2BF3437D2F909DE1F064567A9B2A /* UIImageView+HighlightedWebCache.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = "UIImageView+HighlightedWebCache.m"; path = "SDWebImage/UIImageView+HighlightedWebCache.m"; sourceTree = ""; }; 910B0140B61F5DC829B75D83DABDF372 /* SDImageCacheConfig.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = SDImageCacheConfig.m; path = SDWebImage/SDImageCacheConfig.m; sourceTree = ""; }; 949B7A2A23EE9899A683622D9DA0E241 /* SDAnimatedImageView+WebCache.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = "SDAnimatedImageView+WebCache.m"; path = "SDWebImage/SDAnimatedImageView+WebCache.m"; sourceTree = ""; }; 95405D00873AD67CDFD527CEFAABA52E /* SDAnimatedImageView+WebCache.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = "SDAnimatedImageView+WebCache.h"; path = "SDWebImage/SDAnimatedImageView+WebCache.h"; sourceTree = ""; }; - 95727A880BF527AA01333032F37E55BC /* YYImage.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; name = YYImage.framework; path = YYImage.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 95727A880BF527AA01333032F37E55BC /* YYImage.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = YYImage.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 9584AEE09D90C3F25799F0F89957637A /* SDInternalMacros.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = SDInternalMacros.m; path = SDWebImage/Private/SDInternalMacros.m; sourceTree = ""; }; 961697A809E40D6241E28D9EBBBB99FA /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.0.sdk/System/Library/Frameworks/MobileCoreServices.framework; sourceTree = DEVELOPER_DIR; }; 96987EFB64882140E66D09182116F263 /* YYImageCoder.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = YYImageCoder.h; path = YYImage/YYImageCoder.h; sourceTree = ""; }; @@ -254,13 +254,13 @@ 986E8B432CC6C803E746F5C70EA1022B /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.0.sdk/System/Library/Frameworks/Foundation.framework; sourceTree = DEVELOPER_DIR; }; 988BF49728B04FDE07D09F0B84D4DBA5 /* SDImageCacheDefine.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = SDImageCacheDefine.h; path = SDWebImage/SDImageCacheDefine.h; sourceTree = ""; }; 9AED18FFF53D4616FE343D4C4ADDA6AA /* YYFrameImage.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = YYFrameImage.m; path = YYImage/YYFrameImage.m; sourceTree = ""; }; - 9D940727FF8FB9C785EB98E56350EF41 /* Podfile */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; indentWidth = 2; lastKnownFileType = text; name = Podfile; path = ../Podfile; sourceTree = SOURCE_ROOT; tabWidth = 2; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; + 9D940727FF8FB9C785EB98E56350EF41 /* Podfile */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; includeInIndex = 1; indentWidth = 2; name = Podfile; path = ../Podfile; sourceTree = SOURCE_ROOT; tabWidth = 2; xcLanguageSpecificationIdentifier = xcode.lang.ruby; }; 9ED18A0FB1AC8CE5FA8BF09CC76DE870 /* UIImage+MultiFormat.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = "UIImage+MultiFormat.m"; path = "SDWebImage/UIImage+MultiFormat.m"; sourceTree = ""; }; 9F7AA96660A5FD859D7AFB0AF5D8EB34 /* YYSpriteSheetImage.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = YYSpriteSheetImage.h; path = YYImage/YYSpriteSheetImage.h; sourceTree = ""; }; A6EC32871D989EDFE0C74A0312F957E1 /* SDImageGIFCoder.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = SDImageGIFCoder.m; path = SDWebImage/SDImageGIFCoder.m; sourceTree = ""; }; A6EF636D7BA99DCC1245B44C2D116871 /* SDWebImageCacheKeyFilter.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = SDWebImageCacheKeyFilter.m; path = SDWebImage/SDWebImageCacheKeyFilter.m; sourceTree = ""; }; A8D170B6E5576D920FDC920DD0D02B06 /* SDWebImage-Info.plist */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.plist.xml; path = "SDWebImage-Info.plist"; sourceTree = ""; }; - A964AAF1CFD2B35BF7DF6E3ECEF8F5E8 /* Pods_YBImageBrowserDemo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; name = Pods_YBImageBrowserDemo.framework; path = "Pods-YBImageBrowserDemo.framework"; sourceTree = BUILT_PRODUCTS_DIR; }; + A964AAF1CFD2B35BF7DF6E3ECEF8F5E8 /* Pods_YBImageBrowserDemo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_YBImageBrowserDemo.framework; sourceTree = BUILT_PRODUCTS_DIR; }; A969AB2B0B3E97F1B5DB36C1527A354C /* SDImageGIFCoderInternal.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = SDImageGIFCoderInternal.h; path = SDWebImage/Private/SDImageGIFCoderInternal.h; sourceTree = ""; }; AB3EA8696178796513ABE00468357615 /* SDWebImage.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = SDWebImage.h; path = WebImage/SDWebImage.h; sourceTree = ""; }; ABB73717B3AA95B814EF16578B8A00ED /* SDImageCoder.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = SDImageCoder.h; path = SDWebImage/SDImageCoder.h; sourceTree = ""; }; @@ -580,7 +580,6 @@ BD4CA7DF8553633CD4DDE88B9C393ABB /* Core */, 8D591B03F75733F9E7ABF1005217DC25 /* Support Files */, ); - name = SDWebImage; path = SDWebImage; sourceTree = ""; }; @@ -623,7 +622,6 @@ 376B18D4D3A6FC24AFEAE84886D74545 /* Core */, CF7025499564046CC9E42F6C425CB50B /* Support Files */, ); - name = YYImage; path = YYImage; sourceTree = ""; }; @@ -784,14 +782,15 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0930; - LastUpgradeCheck = 0930; + LastUpgradeCheck = 1020; }; buildConfigurationList = 4821239608C13582E20E6DA73FD5F1F9 /* Build configuration list for PBXProject "Pods" */; compatibilityVersion = "Xcode 8.0"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, + Base, ); mainGroup = CF1408CF629C7361332E53B88F7BD30C; productRefGroup = 723F4A9AF3AB1084FCB6699A2C607D6C /* Products */; @@ -936,6 +935,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; @@ -985,8 +985,7 @@ MTL_FAST_MATH = YES; PRODUCT_NAME = "$(TARGET_NAME)"; STRIP_INSTALLED_PRODUCT = NO; - SWIFT_COMPILATION_MODE = wholemodule; - SWIFT_OPTIMIZATION_LEVEL = "-O"; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SWIFT_VERSION = 4.2; SYMROOT = "${SRCROOT}/../build"; }; @@ -996,6 +995,7 @@ isa = XCBuildConfiguration; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; diff --git a/YBImageBrowser.podspec b/YBImageBrowser.podspec index 4d8e88a..569f3c6 100644 --- a/YBImageBrowser.podspec +++ b/YBImageBrowser.podspec @@ -4,7 +4,7 @@ Pod::Spec.new do |s| s.name = "YBImageBrowser" - s.version = "2.1.7" + s.version = "2.1.8" s.summary = "image browser for iOS (powerful, superior performance)" s.description = <<-DESC image browser for iOS (powerful, superior performance), diff --git a/YBImageBrowser/AuxiliaryView/YBImageBrowserProgressView.m b/YBImageBrowser/AuxiliaryView/YBImageBrowserProgressView.m index 7e3440f..38540d7 100644 --- a/YBImageBrowser/AuxiliaryView/YBImageBrowserProgressView.m +++ b/YBImageBrowser/AuxiliaryView/YBImageBrowserProgressView.m @@ -82,13 +82,13 @@ - (void)drawRect:(CGRect)rect { [bottomPath stroke]; [[UIColor whiteColor] setStroke]; - UIBezierPath *activePath = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:-M_PI / 2.0 endAngle:M_PI * 2 * self->_progress - M_PI / 2.0 clockwise:true]; + UIBezierPath *activePath = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:-M_PI / 2.0 endAngle:M_PI * 2 * _progress - M_PI / 2.0 clockwise:true]; activePath.lineWidth = strokeWidth; activePath.lineCapStyle = kCGLineCapRound; activePath.lineJoinStyle = kCGLineCapRound; [activePath stroke]; - NSString *string = [NSString stringWithFormat:@"%.0lf%@", self->_progress * 100, @"%"]; + NSString *string = [NSString stringWithFormat:@"%.0lf%@", _progress * 100, @"%"]; NSMutableAttributedString *atts = [[NSMutableAttributedString alloc] initWithString:string attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:10], NSForegroundColorAttributeName:[UIColor whiteColor]}]; CGSize size = atts.size; [atts drawAtPoint:CGPointMake(center.x - size.width / 2.0, center.y - size.height / 2.0)]; @@ -152,7 +152,7 @@ - (void)updateConstraints { - (void)showProgress:(CGFloat)progress { self.userInteractionEnabled = NO; - self->_type = YBImageBrowserProgressTypeProgress; + _type = YBImageBrowserProgressTypeProgress; self.drawView.hidden = NO; self.textLabel.hidden = YES; self.imageView.hidden = YES; @@ -164,7 +164,7 @@ - (void)showProgress:(CGFloat)progress { - (void)showLoading { self.userInteractionEnabled = NO; - self->_type = YBImageBrowserProgressTypeLoad; + _type = YBImageBrowserProgressTypeLoad; self.drawView.hidden = YES; self.textLabel.hidden = YES; self.imageView.hidden = NO; @@ -190,7 +190,7 @@ - (void)stopImageViewAnimation { - (void)showText:(NSString *)text click:(void(^)(void))click { self.userInteractionEnabled = click ? YES : NO; - self->_type = YBImageBrowserProgressTypeText; + _type = YBImageBrowserProgressTypeText; self.drawView.hidden = YES; self.textLabel.hidden = NO; self.imageView.hidden = YES; diff --git a/YBImageBrowser/AuxiliaryView/YBImageBrowserSheetView.m b/YBImageBrowser/AuxiliaryView/YBImageBrowserSheetView.m index e29bc56..235818b 100644 --- a/YBImageBrowser/AuxiliaryView/YBImageBrowserSheetView.m +++ b/YBImageBrowser/AuxiliaryView/YBImageBrowserSheetView.m @@ -75,10 +75,10 @@ @implementation YBImageBrowserSheetView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { - self->_heightOfCell = 50; - self->_cancelText = [YBIBCopywriter shareCopywriter].cancel; - self->_maxHeightScale = 0.7; - self->_animateDuration = 0.2; + _heightOfCell = 50; + _cancelText = [YBIBCopywriter shareCopywriter].cancel; + _maxHeightScale = 0.7; + _animateDuration = 0.2; [self addSubview:self.tableView]; } @@ -90,20 +90,20 @@ - (instancetype)initWithFrame:(CGRect)frame { - (void)yb_browserShowSheetViewWithData:(id)data layoutDirection:(YBImageBrowserLayoutDirection)layoutDirection containerSize:(CGSize)containerSize { if (self.actions.count <= 0) return; - self->_data = data; + _data = data; CGFloat width = containerSize.width, height = containerSize.height; CGFloat tableViewHeight = MIN(self.heightOfCell * self.actions.count + self.heightOfCell + 5 + YBIB_HEIGHT_EXTRABOTTOM, height * self.maxHeightScale); - self->_hideFrame = CGRectMake(0, height, width, tableViewHeight); - self->_showFrame = CGRectMake(0, height - tableViewHeight, width, tableViewHeight); + _hideFrame = CGRectMake(0, height, width, tableViewHeight); + _showFrame = CGRectMake(0, height - tableViewHeight, width, tableViewHeight); self.frame = CGRectMake(0, 0, width, height); self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0]; - self.tableView.frame = self->_hideFrame; + self.tableView.frame = _hideFrame; [self.tableView reloadData]; self.footer.frame = CGRectMake(0, 0, width, YBIB_HEIGHT_EXTRABOTTOM); - [UIView animateWithDuration:self->_animateDuration animations:^{ + [UIView animateWithDuration:_animateDuration animations:^{ self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.35]; self.tableView.frame = self->_showFrame; }]; @@ -120,7 +120,7 @@ - (void)yb_browserHideSheetViewWithAnimation:(BOOL)animation { [self removeFromSuperview]; }; if (animation) { - [UIView animateWithDuration:self->_animateDuration animations:animationsBlock completion:completionBlock]; + [UIView animateWithDuration:_animateDuration animations:animationsBlock completion:completionBlock]; } else { animationsBlock(); completionBlock(NO); @@ -175,13 +175,13 @@ - (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_browserSaveToPhotoAlbum)] && [self->_data respondsToSelector:@selector(yb_browserAllowSaveToPhotoAlbum)] && [self->_data yb_browserAllowSaveToPhotoAlbum]) { - [self->_data yb_browserSaveToPhotoAlbum]; + if ([_data respondsToSelector:@selector(yb_browserSaveToPhotoAlbum)] && [_data respondsToSelector:@selector(yb_browserAllowSaveToPhotoAlbum)] && [_data yb_browserAllowSaveToPhotoAlbum]) { + [_data yb_browserSaveToPhotoAlbum]; } else { [[UIApplication sharedApplication].keyWindow yb_showForkTipView:[YBIBCopywriter shareCopywriter].unableToSave]; } } else { - self.actions[indexPath.row].action(self->_data); + self.actions[indexPath.row].action(_data); } } [self yb_browserHideSheetViewWithAnimation:YES]; diff --git a/YBImageBrowser/AuxiliaryView/YBImageBrowserTipView.m b/YBImageBrowser/AuxiliaryView/YBImageBrowserTipView.m index 06ccca3..82f299c 100644 --- a/YBImageBrowser/AuxiliaryView/YBImageBrowserTipView.m +++ b/YBImageBrowser/AuxiliaryView/YBImageBrowserTipView.m @@ -75,7 +75,7 @@ @implementation YBImageBrowserTipView - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { - self->_tipType = YBImageBrowserTipTypeNone; + _tipType = YBImageBrowserTipTypeNone; self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.8]; self.userInteractionEnabled = NO; @@ -98,7 +98,7 @@ - (void)updateConstraints { } - (void)layoutSubviews { - if (self->_tipType != YBImageBrowserTipTypeNone) { + if (_tipType != YBImageBrowserTipTypeNone) { [self _startAnimation]; } [super layoutSubviews]; @@ -108,7 +108,7 @@ - (void)layoutSubviews { - (void)startAnimationWithText:(NSString *)text type:(YBImageBrowserTipType)tipType { self.textLabel.text = text; - self->_tipType = tipType; + _tipType = tipType; [self setNeedsLayout]; } @@ -129,7 +129,7 @@ - (void)_startAnimation { CGFloat r = 13.0; CGFloat x = self.bounds.size.width / 2.0; CGFloat y = 38.0; - switch (self->_tipType) { + switch (_tipType) { case YBImageBrowserTipTypeHook: { [bezierPath moveToPoint:CGPointMake(x - r - r / 2, y)]; [bezierPath addLineToPoint:CGPointMake(x - r / 2, y + r)]; diff --git a/YBImageBrowser/AuxiliaryView/YBImageBrowserToolBar.m b/YBImageBrowser/AuxiliaryView/YBImageBrowserToolBar.m index 54aee54..5924cfa 100644 --- a/YBImageBrowser/AuxiliaryView/YBImageBrowserToolBar.m +++ b/YBImageBrowser/AuxiliaryView/YBImageBrowserToolBar.m @@ -45,8 +45,8 @@ - (instancetype)initWithFrame:(CGRect)frame - (void)setOperationButtonImage:(UIImage *)image title:(NSString *)title operation:(YBImageBrowserToolBarOperationBlock)operation { [self.operationButton setImage:image forState:UIControlStateNormal]; [self.operationButton setTitle:title forState:UIControlStateNormal]; - self->_operation = operation; - self->_operationType = YBImageBrowserToolBarOperationTypeCustom; + _operation = operation; + _operationType = YBImageBrowserToolBarOperationTypeCustom; } - (void)hideOperationButton { @@ -67,7 +67,7 @@ - (void)yb_browserUpdateLayoutWithDirection:(YBImageBrowserLayoutDirection)layou } - (void)yb_browserPageIndexChanged:(NSUInteger)pageIndex totalPage:(NSUInteger)totalPage data:(id)data { - switch (self->_operationType) { + switch (_operationType) { case YBImageBrowserToolBarOperationTypeSave: { if ([data respondsToSelector:@selector(yb_browserSaveToPhotoAlbum)] && [data respondsToSelector:@selector(yb_browserAllowSaveToPhotoAlbum)] && [data yb_browserAllowSaveToPhotoAlbum]) { self.operationButton.hidden = NO; @@ -83,39 +83,39 @@ - (void)yb_browserPageIndexChanged:(NSUInteger)pageIndex totalPage:(NSUInteger)t } break; case YBImageBrowserToolBarOperationTypeCustom: { - self.operationButton.hidden = !self->_operation; + self.operationButton.hidden = !_operation; } break; } - self->_data = data; + _data = data; if (totalPage <= 1) { self.indexLabel.hidden = YES; } else { self.indexLabel.hidden = NO; - self.indexLabel.text = [NSString stringWithFormat:@"%ld/%ld", pageIndex + 1, totalPage]; + self.indexLabel.text = [NSString stringWithFormat:@"%ld/%ld", (unsigned long)(pageIndex + 1), (unsigned long)totalPage]; } } #pragma mark - event - (void)clickOperationButton:(UIButton *)button { - switch (self->_operationType) { + switch (_operationType) { case YBImageBrowserToolBarOperationTypeSave: { - if ([self->_data respondsToSelector:@selector(yb_browserSaveToPhotoAlbum)]) { - [self->_data yb_browserSaveToPhotoAlbum]; + if ([_data respondsToSelector:@selector(yb_browserSaveToPhotoAlbum)]) { + [_data yb_browserSaveToPhotoAlbum]; } else { [[UIApplication sharedApplication].keyWindow yb_showForkTipView:[YBIBCopywriter shareCopywriter].unableToSave]; } } break; case YBImageBrowserToolBarOperationTypeMore: { - self.yb_browserShowSheetViewBlock(self->_data); + self.yb_browserShowSheetViewBlock(_data); } break; case YBImageBrowserToolBarOperationTypeCustom: { - if (self->_operation) { - self->_operation(self->_data); + if (_operation) { + _operation(_data); } } break; diff --git a/YBImageBrowser/Base/YBImageBrowserView.m b/YBImageBrowser/Base/YBImageBrowserView.m index b3a80e7..f195562 100644 --- a/YBImageBrowser/Base/YBImageBrowserView.m +++ b/YBImageBrowser/Base/YBImageBrowserView.m @@ -32,7 +32,7 @@ @implementation YBImageBrowserView #pragma mark - life cycle - (void)dealloc { - self->_dataCache = nil; + _dataCache = nil; } - (instancetype)initWithFrame:(CGRect)frame { @@ -61,24 +61,24 @@ - (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(nonnull UIColl } - (void)initVars { - self->_layoutDirection = YBImageBrowserLayoutDirectionUnknown; - self->_reuseIdentifierSet = [NSMutableSet set]; - self->_isDealingScreenRotation = NO; - self->_bodyIsInCenter = YES; - self->_currentIndex = NSUIntegerMax; - self->_isDealedSELInitializeFirst = NO; - self->_cacheCountLimit = 8; + _layoutDirection = YBImageBrowserLayoutDirectionUnknown; + _reuseIdentifierSet = [NSMutableSet set]; + _isDealingScreenRotation = NO; + _bodyIsInCenter = YES; + _currentIndex = NSUIntegerMax; + _isDealedSELInitializeFirst = NO; + _cacheCountLimit = 8; } #pragma mark - public - (void)updateLayoutWithDirection:(YBImageBrowserLayoutDirection)layoutDirection containerSize:(CGSize)containerSize { - if (self->_layoutDirection == layoutDirection) return; - self->_isDealingScreenRotation = YES; + if (_layoutDirection == layoutDirection) return; + _isDealingScreenRotation = YES; - self->_containerSize = containerSize; - self.frame = CGRectMake(0, 0, self->_containerSize.width, self->_containerSize.height); - self->_layoutDirection = layoutDirection; + _containerSize = containerSize; + self.frame = CGRectMake(0, 0, _containerSize.width, _containerSize.height); + _layoutDirection = layoutDirection; if (self.superview) { // Notice 'visibleCells' layout direction changed, can't use '-reloadData' because it will triggering '-prepareForReuse' of cell. @@ -92,7 +92,7 @@ - (void)updateLayoutWithDirection:(YBImageBrowserLayoutDirection)layoutDirection } [self layoutIfNeeded]; - self->_isDealingScreenRotation = NO; + _isDealingScreenRotation = NO; } - (void)scrollToPageWithIndex:(NSInteger)index { @@ -111,7 +111,7 @@ - (void)scrollToPageWithIndex:(NSInteger)index { } - (void)yb_reloadData { - self->_dataCache = nil; + _dataCache = nil; [self reloadData]; } @@ -122,17 +122,17 @@ - (void)yb_reloadData { - (id)dataAtIndex:(NSUInteger)index { if (index < 0 || index >= [self.yb_dataSource yb_numberOfCellForImageBrowserView:self]) return nil; - if (!self->_dataCache) { - self->_dataCache = [NSCache new]; - self->_dataCache.countLimit = self.cacheCountLimit; + if (!_dataCache) { + _dataCache = [NSCache new]; + _dataCache.countLimit = self.cacheCountLimit; } id data; - if (self->_dataCache && [self->_dataCache objectForKey:@(index)]) { - data = [self->_dataCache objectForKey:@(index)]; + if (_dataCache && [_dataCache objectForKey:@(index)]) { + data = [_dataCache objectForKey:@(index)]; } else { data = [self.yb_dataSource yb_imageBrowserView:self dataForCellAtIndex:index]; - [self->_dataCache setObject:data forKey:@(index)]; + [_dataCache setObject:data forKey:@(index)]; } return data; } @@ -166,20 +166,20 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell NSAssert(cellClass, @"the class get from '-yb_classOfBrowserCell' is invalid"); NSString *identifier = NSStringFromClass(cellClass); - if (![self->_reuseIdentifierSet containsObject:cellClass]) { + if (![_reuseIdentifierSet containsObject:cellClass]) { NSString *path = [[NSBundle mainBundle] pathForResource:identifier ofType:@"nib"]; if (path) { [collectionView registerNib:[UINib nibWithNibName:identifier bundle:nil] forCellWithReuseIdentifier:identifier]; } else { [collectionView registerClass:cellClass forCellWithReuseIdentifier:identifier]; } - [self->_reuseIdentifierSet addObject:cellClass]; + [_reuseIdentifierSet addObject:cellClass]; } UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; NSAssert(cell, @"your custom cell must be subclass of 'UICollectionViewCell'"); NSAssert([cell respondsToSelector:@selector(yb_initializeBrowserCellWithData:layoutDirection:containerSize:)], @"your custom cell must conforms '' and implement '-yb_initializeBrowserCellWithData:layoutDirection:containerSize:'"); - [cell yb_initializeBrowserCellWithData:data layoutDirection:self->_layoutDirection containerSize:self->_containerSize]; + [cell yb_initializeBrowserCellWithData:data layoutDirection:_layoutDirection containerSize:_containerSize]; if ([cell respondsToSelector:@selector(yb_browserStatusBarOrientationBefore:)]) { [cell yb_browserStatusBarOrientationBefore:self.statusBarOrientationBefore]; @@ -221,9 +221,9 @@ - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cell }]; } - if ([cell respondsToSelector:@selector(yb_browserInitializeFirst:)] && !self->_isDealedSELInitializeFirst) { - self->_isDealedSELInitializeFirst = YES; - [cell yb_browserInitializeFirst:self->_currentIndex == indexPath.row]; + if ([cell respondsToSelector:@selector(yb_browserInitializeFirst:)] && !_isDealedSELInitializeFirst) { + _isDealedSELInitializeFirst = YES; + [cell yb_browserInitializeFirst:_currentIndex == indexPath.row]; } if (collectionView.window && self.shouldPreload) { @@ -240,8 +240,8 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView { NSUInteger index = (NSUInteger)(indexF + 0.5); BOOL isInCenter = indexF <= (NSInteger)indexF + 0.001 && indexF >= (NSInteger)indexF - 0.001; - if (self->_bodyIsInCenter != isInCenter) { - self->_bodyIsInCenter = isInCenter; + if (_bodyIsInCenter != isInCenter) { + _bodyIsInCenter = isInCenter; NSArray *> *cells = [self visibleCells]; [cells enumerateObjectsUsingBlock:^(UICollectionViewCell * _Nonnull cell, NSUInteger idx, BOOL * _Nonnull stop) { @@ -252,7 +252,7 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView { } if (index >= [self.yb_dataSource yb_numberOfCellForImageBrowserView:self]) return; - if (self.currentIndex != index && !self->_isDealingScreenRotation) { + if (self.currentIndex != index && !_isDealingScreenRotation) { self.currentIndex = index; [self.yb_delegate yb_imageBrowserView:self pageIndexChanged:self.currentIndex]; diff --git a/YBImageBrowser/Helper/YBIBTransitionManager.m b/YBImageBrowser/Helper/YBIBTransitionManager.m index 95b8105..7a5cc78 100644 --- a/YBImageBrowser/Helper/YBIBTransitionManager.m +++ b/YBImageBrowser/Helper/YBIBTransitionManager.m @@ -26,7 +26,7 @@ - (instancetype)init { self = [super init]; if (self) { self.transitioning = NO; - self->_enter = NO; + _enter = NO; } return self; } @@ -35,7 +35,7 @@ - (instancetype)init { - (void)animationEnded:(BOOL)transitionCompleted { if (self.imageBrowser && self.imageBrowser.delegate && [self.imageBrowser.delegate respondsToSelector:@selector(yb_imageBrowser:transitionAnimationEndedWithIsEnter:)]) { - [self.imageBrowser.delegate yb_imageBrowser:self.imageBrowser transitionAnimationEndedWithIsEnter:self->_enter]; + [self.imageBrowser.delegate yb_imageBrowser:self.imageBrowser transitionAnimationEndedWithIsEnter:_enter]; } } @@ -52,7 +52,7 @@ - (void)animateTransition:(id )transitionC // Enter if (toController.isBeingPresented) { - self->_enter = YES; + _enter = YES; self.transitioning = YES; switch (self.imageBrowser.enterTransitionType) { case YBImageBrowserTransitionTypeNone: { @@ -99,48 +99,65 @@ - (void)animateTransition:(id )transitionC // Out if (fromController.isBeingDismissed) { - self->_enter = NO; + + void(^noneBlock)(void) = ^{ + [self completeTransition:transitionContext isEnter:NO]; + }; + + void(^fadeBlock)(void) = ^{ + UIView *fromAnimateView = [self out_fromAnimateView]; + [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{ + fromAnimateView.alpha = 0; + fromView.alpha = 0; + } completion:^(BOOL finished) { + [self completeTransition:transitionContext isEnter:NO]; + }]; + }; + + void(^coherentBlock)(void) = ^{ + UIView *fromAnimateView = [self out_fromAnimateView]; + if (fromAnimateView) { + CGRect fromFrame = fromAnimateView.frame; + CGRect toFrame = [self out_toFrameWithView:fromAnimateView.superview]; + if (CGRectEqualToRect(toFrame, CGRectZero)) { + fadeBlock(); + return; + } + + [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{ + fromView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0]; + id sourceObj = [self out_toSourceObj]; + if ([sourceObj isKindOfClass:UIView.class]) + fromAnimateView.contentMode = ((UIImageView *)sourceObj).contentMode; + + if ([fromAnimateView isKindOfClass:UIImageView.class]) { + fromAnimateView.frame = toFrame; + } else { + CGFloat scale = MAX(toFrame.size.width / fromFrame.size.width, toFrame.size.height / fromFrame.size.height); + fromAnimateView.center = CGPointMake(toFrame.size.width * fromAnimateView.layer.anchorPoint.x + toFrame.origin.x, toFrame.size.height * fromAnimateView.layer.anchorPoint.y + toFrame.origin.y);; + fromAnimateView.transform = CGAffineTransformScale(fromAnimateView.transform, scale, scale); + } + } completion:^(BOOL finished) { + [self completeTransition:transitionContext isEnter:NO]; + }]; + } else { + [self completeTransition:transitionContext isEnter:NO]; + } + }; + + _enter = NO; self.transitioning = YES; switch (self.imageBrowser.outTransitionType) { case YBImageBrowserTransitionTypeNone: { - [self completeTransition:transitionContext isEnter:NO]; + noneBlock(); } break; case YBImageBrowserTransitionTypeFade: { - UIView *fromAnimateView = [self out_fromAnimateView]; - [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{ - fromAnimateView.alpha = 0; - fromView.alpha = 0; - } completion:^(BOOL finished) { - [self completeTransition:transitionContext isEnter:NO]; - }]; + fadeBlock(); } break; case YBImageBrowserTransitionTypeCoherent: { - UIView *fromAnimateView = [self out_fromAnimateView]; - if (fromAnimateView) { - CGRect fromFrame = fromAnimateView.frame; - CGRect toFrame = [self out_toFrameWithView:fromAnimateView.superview]; - [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{ - - fromView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0]; - id sourceObj = [self out_toSourceObj]; - if ([sourceObj isKindOfClass:UIView.class]) - fromAnimateView.contentMode = ((UIImageView *)sourceObj).contentMode; - - if ([fromAnimateView isKindOfClass:UIImageView.class]) { - fromAnimateView.frame = toFrame; - } else { - CGFloat scale = MAX(toFrame.size.width / fromFrame.size.width, toFrame.size.height / fromFrame.size.height); - fromAnimateView.center = CGPointMake(toFrame.size.width * fromAnimateView.layer.anchorPoint.x + toFrame.origin.x, toFrame.size.height * fromAnimateView.layer.anchorPoint.y + toFrame.origin.y);; - fromAnimateView.transform = CGAffineTransformScale(fromAnimateView.transform, scale, scale); - } - } completion:^(BOOL finished) { - [self completeTransition:transitionContext isEnter:NO]; - }]; - } else { - [self completeTransition:transitionContext isEnter:NO]; - } + coherentBlock(); } break; } @@ -215,9 +232,7 @@ - (UIView *)out_fromAnimateView { } - (CGRect)out_toFrameWithView:(UIView *)view { - CGFloat width = [UIScreen mainScreen].bounds.size.width, - height = [UIScreen mainScreen].bounds.size.height; - CGRect frame = CGRectMake(width / 2, height / 2, 1, 1); + CGRect frame = CGRectZero; id sourceObj = [self out_toSourceObj]; if (!sourceObj || ![sourceObj respondsToSelector:@selector(bounds)]) { return frame; diff --git a/YBImageBrowser/Helper/YBIBUtilities.h b/YBImageBrowser/Helper/YBIBUtilities.h index 261009a..ea9269c 100644 --- a/YBImageBrowser/Helper/YBIBUtilities.h +++ b/YBImageBrowser/Helper/YBIBUtilities.h @@ -47,9 +47,11 @@ CFAbsoluteTime linkTime = (CFAbsoluteTimeGetCurrent() - startTime); \ YBIBLOG(@"countTimeWithCode: %f ms", linkTime * 1000.0); -UIWindow *YBIBGetNormalWindow(void); +UIWindow * _Nonnull YBIBGetNormalWindow(void); -UIViewController *YBIBGetTopController(void); +UIViewController * _Nullable YBIBGetTopController(void); + +BOOL YBIBLowMemory(void); NS_ASSUME_NONNULL_BEGIN diff --git a/YBImageBrowser/Helper/YBIBUtilities.m b/YBImageBrowser/Helper/YBIBUtilities.m index e232a94..e1e2d01 100644 --- a/YBImageBrowser/Helper/YBIBUtilities.m +++ b/YBImageBrowser/Helper/YBIBUtilities.m @@ -32,13 +32,33 @@ topController = nextResponder; } else { topController = window.rootViewController; - while (topController.presentedViewController) { - topController = topController.presentedViewController; + } + + while ([topController isKindOfClass:UITabBarController.class] || [topController isKindOfClass:UINavigationController.class]) { + if ([topController isKindOfClass:UITabBarController.class]) { + topController = ((UITabBarController *)topController).selectedViewController; + } else if ([topController isKindOfClass:UINavigationController.class]) { + topController = ((UINavigationController *)topController).topViewController; } } + + while (topController.presentedViewController) { + topController = topController.presentedViewController; + } + return topController; } +BOOL YBIBLowMemory(void) { + static BOOL lowMemory = NO; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + unsigned long long physicalMemory = [[NSProcessInfo processInfo] physicalMemory]; + lowMemory = physicalMemory > 0 && physicalMemory < 1024 * 1024 * 1500; + }); + return lowMemory; +} + @implementation YBIBUtilities diff --git a/YBImageBrowser/ImageBrowse/YBImageBrowseCell.m b/YBImageBrowser/ImageBrowse/YBImageBrowseCell.m index 018afd7..524a58d 100644 --- a/YBImageBrowser/ImageBrowse/YBImageBrowseCell.m +++ b/YBImageBrowser/ImageBrowse/YBImageBrowseCell.m @@ -66,7 +66,7 @@ - (instancetype)initWithFrame:(CGRect)frame { - (void)willMoveToWindow:(UIWindow *)newWindow { [super willMoveToWindow:newWindow]; - self->_outTransitioning = NO; + _outTransitioning = NO; } - (void)prepareForReuse { @@ -82,22 +82,22 @@ - (void)prepareForReuse { } - (void)initVars { - self->_zooming = NO; - self->_dragging = NO; - self->_bodyInCenter = YES; - self->_outTransitioning = NO; - self->_layoutDirection = YBImageBrowserLayoutDirectionUnknown; - self->_containerSize = CGSizeMake(1, 1); + _zooming = NO; + _dragging = NO; + _bodyInCenter = YES; + _outTransitioning = NO; + _layoutDirection = YBImageBrowserLayoutDirectionUnknown; + _containerSize = CGSizeMake(1, 1); - self->_gestureInteractionStartPoint = CGPointZero; - self->_gestureInteracting = NO; + _gestureInteractionStartPoint = CGPointZero; + _gestureInteracting = NO; } #pragma mark - - (void)yb_initializeBrowserCellWithData:(id)data layoutDirection:(YBImageBrowserLayoutDirection)layoutDirection containerSize:(CGSize)containerSize { - self->_containerSize = containerSize; - self->_layoutDirection = layoutDirection; + _containerSize = containerSize; + _layoutDirection = layoutDirection; if (![data isKindOfClass:YBImageBrowseCellData.class]) return; self.cellData = data; @@ -108,12 +108,12 @@ - (void)yb_initializeBrowserCellWithData:(id)dat } - (void)yb_browserLayoutDirectionChanged:(YBImageBrowserLayoutDirection)layoutDirection containerSize:(CGSize)containerSize { - self->_containerSize = containerSize; - self->_layoutDirection = layoutDirection; + _containerSize = containerSize; + _layoutDirection = layoutDirection; [self hideTailoringImageView]; - if (self->_gestureInteracting) { + if (_gestureInteracting) { [self restoreGestureInteractionWithDuration:0]; } @@ -122,7 +122,7 @@ - (void)yb_browserLayoutDirectionChanged:(YBImageBrowserLayoutDirection)layoutDi } - (void)yb_browserBodyIsInTheCenter:(BOOL)isIn { - self->_bodyInCenter = isIn; + _bodyInCenter = isIn; } - (UIView *)yb_browserCurrentForegroundView { @@ -130,11 +130,11 @@ - (UIView *)yb_browserCurrentForegroundView { } - (void)yb_browserSetGestureInteractionProfile:(YBIBGestureInteractionProfile *)giProfile { - self->_giProfile = giProfile; + _giProfile = giProfile; } - (void)yb_browserStatusBarOrientationBefore:(UIInterfaceOrientation)orientation { - self->_statusBarOrientationBefore = orientation; + _statusBarOrientationBefore = orientation; } #pragma mark - @@ -169,21 +169,21 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView { } - (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view { - self->_zooming = YES; + _zooming = YES; [self hideTailoringImageView]; } - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(nullable UIView *)view atScale:(CGFloat)scale { - self->_zooming = NO; + _zooming = NO; } - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { - self->_dragging = YES; + _dragging = YES; [self hideTailoringImageView]; } - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { - self->_dragging = NO; + _dragging = NO; } #pragma mark - @@ -199,10 +199,14 @@ - (void)addGesture { tapSingle.numberOfTapsRequired = 1; UITapGestureRecognizer *tapDouble = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(respondsToTapDouble:)]; tapDouble.numberOfTapsRequired = 2; - [tapSingle requireGestureRecognizerToFail:tapDouble]; UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(respondsToPan:)]; pan.maximumNumberOfTouches = 1; pan.delegate = self; + + [tapSingle requireGestureRecognizerToFail:tapDouble]; + [tapSingle requireGestureRecognizerToFail:pan]; + [tapDouble requireGestureRecognizerToFail:pan]; + [self.mainContentView addGestureRecognizer:tapSingle]; [self.mainContentView addGestureRecognizer:tapDouble]; [self.mainContentView addGestureRecognizer:pan]; @@ -235,49 +239,50 @@ - (BOOL)currentIsLargeImageBrowsing { } - (void)respondsToPan:(UIPanGestureRecognizer *)pan { - if ((CGRectIsEmpty(self.mainImageView.frame) || !self.mainImageView.image) || self->_giProfile.disable) return; + if ((CGRectIsEmpty(self.mainImageView.frame) || !self.mainImageView.image) || _giProfile.disable) return; CGPoint point = [pan locationInView:self]; if (pan.state == UIGestureRecognizerStateBegan) { - self->_gestureInteractionStartPoint = point; + _gestureInteractionStartPoint = point; } else if (pan.state == UIGestureRecognizerStateCancelled || pan.state == UIGestureRecognizerStateEnded || pan.state == UIGestureRecognizerStateRecognized || pan.state == UIGestureRecognizerStateFailed) { // END - if (self->_gestureInteracting) { + if (_gestureInteracting) { CGPoint velocity = [pan velocityInView:self.mainContentView]; - BOOL velocityArrive = ABS(velocity.y) > self->_giProfile.dismissVelocityY; - BOOL distanceArrive = ABS(point.y - self->_gestureInteractionStartPoint.y) > self->_containerSize.height * self->_giProfile.dismissScale; + BOOL velocityArrive = ABS(velocity.y) > _giProfile.dismissVelocityY; + BOOL distanceArrive = ABS(point.y - _gestureInteractionStartPoint.y) > _containerSize.height * _giProfile.dismissScale; BOOL shouldDismiss = distanceArrive || velocityArrive; if (shouldDismiss) { [self browserDismiss]; } else { - [self restoreGestureInteractionWithDuration:self->_giProfile.restoreDuration]; + YBIBLOG(@"restore"); + [self restoreGestureInteractionWithDuration:_giProfile.restoreDuration]; } } } else if (pan.state == UIGestureRecognizerStateChanged) { CGPoint velocity = [pan velocityInView:self.mainContentView]; - CGFloat triggerDistance = self->_giProfile.triggerDistance; + CGFloat triggerDistance = _giProfile.triggerDistance; - BOOL startPointValid = !CGPointEqualToPoint(self->_gestureInteractionStartPoint, CGPointZero); - BOOL distanceArrive = ABS(point.x - self->_gestureInteractionStartPoint.x) < triggerDistance && ABS(velocity.x) < 500; - BOOL upArrive = point.y - self->_gestureInteractionStartPoint.y > triggerDistance && self.mainContentView.contentOffset.y <= 1, - downArrive = point.y - self->_gestureInteractionStartPoint.y < -triggerDistance && self.mainContentView.contentOffset.y + self.mainContentView.bounds.size.height >= MAX(self.mainContentView.contentSize.height, self.mainContentView.bounds.size.height) - 1; + BOOL startPointValid = !CGPointEqualToPoint(_gestureInteractionStartPoint, CGPointZero); + BOOL distanceArrive = ABS(point.x - _gestureInteractionStartPoint.x) < triggerDistance && ABS(velocity.x) < 500; + BOOL upArrive = point.y - _gestureInteractionStartPoint.y > triggerDistance && self.mainContentView.contentOffset.y <= 1; + BOOL downArrive = point.y - _gestureInteractionStartPoint.y < -triggerDistance && self.mainContentView.contentOffset.y + self.mainContentView.bounds.size.height >= MAX(self.mainContentView.contentSize.height, self.mainContentView.bounds.size.height) - 1; - BOOL shouldStart = startPointValid && !self->_gestureInteracting && (upArrive || downArrive) && distanceArrive && self->_bodyInCenter && !self->_zooming; + BOOL shouldStart = startPointValid && !_gestureInteracting && (upArrive || downArrive) && distanceArrive && _bodyInCenter && !_zooming; // START if (shouldStart) { - if ([UIApplication sharedApplication].statusBarOrientation != self->_statusBarOrientationBefore) { + if ([UIApplication sharedApplication].statusBarOrientation != _statusBarOrientationBefore) { [self browserDismiss]; } else { [self hideTailoringImageView]; - self->_gestureInteractionStartPoint = point; + _gestureInteractionStartPoint = point; CGRect startFrame = self.mainContentView.frame; CGFloat anchorX = point.x / startFrame.size.width, @@ -289,19 +294,19 @@ - (void)respondsToPan:(UIPanGestureRecognizer *)pan { self.yb_browserScrollEnabledBlock(NO); self.yb_browserToolBarHiddenBlock(YES); - self->_gestureInteracting = YES; + _gestureInteracting = YES; } } // CHNAGE - if (self->_gestureInteracting) { + if (_gestureInteracting) { self.mainContentView.center = point; - CGFloat scale = 1 - ABS(point.y - self->_gestureInteractionStartPoint.y) / (self->_containerSize.height * 1.2); + CGFloat scale = 1 - ABS(point.y - _gestureInteractionStartPoint.y) / (_containerSize.height * 1.2); if (scale > 1) scale = 1; if (scale < 0.35) scale = 0.35; self.mainContentView.transform = CGAffineTransformMakeScale(scale, scale); - CGFloat alpha = 1 - ABS(point.y - self->_gestureInteractionStartPoint.y) / (self->_containerSize.height * 1.1); + CGFloat alpha = 1 - ABS(point.y - _gestureInteractionStartPoint.y) / (_containerSize.height * 1.1); if (alpha > 1) alpha = 1; if (alpha < 0) alpha = 0; self.yb_browserChangeAlphaBlock(alpha, 0); @@ -349,7 +354,7 @@ - (void)removeObserverForDataState { } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { - if (!self->_outTransitioning && object == self.cellData && [keyPath isEqualToString:@"dataState"]) { + if (!_outTransitioning && object == self.cellData && [keyPath isEqualToString:@"dataState"]) { [self cellDataStateChanged]; } } @@ -357,11 +362,12 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N #pragma mark - private - (void)browserDismiss { - self->_outTransitioning = YES; + _outTransitioning = YES; [self hideTailoringImageView]; [self.contentView yb_hideProgressView]; [self yb_hideProgressView]; self.yb_browserDismissBlock(); + _gestureInteracting = NO; } - (void)cellDataStateChanged { @@ -375,7 +381,7 @@ - (void)cellDataStateChanged { case YBImageBrowseCellDataStateImageReady: { if (self.mainImageView.image != data.image) { self.mainImageView.image = data.image; - [self updateMainContentViewLayoutWithContainerSize:self->_containerSize fillType:[data getFillTypeWithLayoutDirection:self->_layoutDirection]]; + [self updateMainContentViewLayoutWithContainerSize:_containerSize fillType:[data getFillTypeWithLayoutDirection:_layoutDirection]]; } } break; @@ -392,7 +398,7 @@ - (void)cellDataStateChanged { case YBImageBrowseCellDataStateCompressImageReady: { if (self.mainImageView.image != data.compressImage) { self.mainImageView.image = data.compressImage; - [self updateMainContentViewLayoutWithContainerSize:self->_containerSize fillType:[data getFillTypeWithLayoutDirection:self->_layoutDirection]]; + [self updateMainContentViewLayoutWithContainerSize:_containerSize fillType:[data getFillTypeWithLayoutDirection:_layoutDirection]]; } } break; @@ -400,7 +406,7 @@ - (void)cellDataStateChanged { // If the image has been display, discard the thumb image. if (!self.mainImageView.image) { self.mainImageView.image = data.thumbImage; - [self updateMainContentViewLayoutWithContainerSize:self->_containerSize fillType:[data getFillTypeWithLayoutDirection:self->_layoutDirection]]; + [self updateMainContentViewLayoutWithContainerSize:_containerSize fillType:[data getFillTypeWithLayoutDirection:_layoutDirection]]; } } break; @@ -473,18 +479,18 @@ - (void)updateMainContentViewLayoutWithContainerSize:(CGSize)containerSize fillT } - (void)showTailoringImageView:(UIImage *)image { - if (self->_gestureInteracting) return; + if (_gestureInteracting) return; if (!self.tailoringImageView.superview) { [self.contentView addSubview:self.tailoringImageView]; } - self.tailoringImageView.frame = CGRectMake(0, 0, self->_containerSize.width, self->_containerSize.height); + self.tailoringImageView.frame = CGRectMake(0, 0, _containerSize.width, _containerSize.height); self.tailoringImageView.hidden = NO; self.tailoringImageView.image = image; } - (void)hideTailoringImageView { // Don't use 'getter' method, because it's according to the need to load. - if (self->_tailoringImageView) { + if (_tailoringImageView) { self.tailoringImageView.hidden = YES; } } diff --git a/YBImageBrowser/ImageBrowse/YBImageBrowseCellData.h b/YBImageBrowser/ImageBrowse/YBImageBrowseCellData.h index 8cf2719..1ec605e 100644 --- a/YBImageBrowser/ImageBrowse/YBImageBrowseCellData.h +++ b/YBImageBrowser/ImageBrowse/YBImageBrowseCellData.h @@ -86,7 +86,7 @@ When the image exceeds this texture size, it will be compressed asynchronously a /** You can set any data. */ @property (nonatomic, strong, nullable) id extraData; -/** The default is YES. +/** The default is YES. (The default is NO which low memory device.) If the image decoding lead to interactive caton, you can set it to YES. When decoding asynchronously, there will be more time consumption. */ @property (nonatomic, class) BOOL shouldDecodeAsynchronously; diff --git a/YBImageBrowser/ImageBrowse/YBImageBrowseCellData.m b/YBImageBrowser/ImageBrowse/YBImageBrowseCellData.m index 88ab3d8..ca41e99 100644 --- a/YBImageBrowser/ImageBrowse/YBImageBrowseCellData.m +++ b/YBImageBrowser/ImageBrowse/YBImageBrowseCellData.m @@ -34,9 +34,13 @@ @implementation YBImageBrowseCellData #pragma mark - life cycle ++ (void)initialize { + _shouldDecodeAsynchronously = !YBIBLowMemory(); +} + - (void)dealloc { - if (self->_downloadToken) { - [YBIBWebImageManager cancelTaskWithDownloadToken:self->_downloadToken]; + if (_downloadToken) { + [YBIBWebImageManager cancelTaskWithDownloadToken:_downloadToken]; } } @@ -49,15 +53,15 @@ - (instancetype)init { } - (void)initVars { - self->_maxZoomScale = 0; - self->_verticalfillType = YBImageBrowseFillTypeUnknown; - self->_horizontalfillType = YBImageBrowseFillTypeUnknown; - self->_allowSaveToPhotoAlbum = YES; - self->_allowShowSheetView = YES; + _maxZoomScale = 0; + _verticalfillType = YBImageBrowseFillTypeUnknown; + _horizontalfillType = YBImageBrowseFillTypeUnknown; + _allowSaveToPhotoAlbum = YES; + _allowShowSheetView = YES; - self->_cutting = NO; + _cutting = NO; - self->_loading = NO; + _loading = NO; } #pragma mark - @@ -234,7 +238,7 @@ - (void)downloadImage { if (!self.url) return; self.dataState = YBImageBrowseCellDataStateIsDownloading; - self->_downloadToken = [YBIBWebImageManager downloadImageWithURL:self.url progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) { + _downloadToken = [YBIBWebImageManager downloadImageWithURL:self.url progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) { CGFloat value = receivedSize * 1.0 / expectedSize ?: 0; self->_downloadProgress = value; @@ -307,8 +311,8 @@ - (void)compressingImage { - (void)cuttingImageToRect:(CGRect)rect complete:(void(^)(UIImage *image))complete { if (!self.image) return; - if (self->_cutting) return; - self->_cutting = YES; + if (_cutting) return; + _cutting = YES; CGFloat zoomScale = self.zoomScale; BOOL (^isCancelled)(void) = ^BOOL{ diff --git a/YBImageBrowser/VideoBrowse/YBVideoBrowseActionBar.m b/YBImageBrowser/VideoBrowse/YBVideoBrowseActionBar.m index da5b42d..ceb175d 100644 --- a/YBImageBrowser/VideoBrowse/YBVideoBrowseActionBar.m +++ b/YBImageBrowser/VideoBrowse/YBVideoBrowseActionBar.m @@ -53,7 +53,7 @@ @implementation YBVideoBrowseActionBar - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { - self->_isDragging = NO; + _isDragging = NO; [self.layer addSublayer:self.gradientLayer]; [self addSubview:self.playButton]; @@ -90,7 +90,7 @@ - (void)pause { - (void)play { self.playButton.selected = YES; - self->_isDragging = NO; + _isDragging = NO; self.slider.userInteractionEnabled = YES; } @@ -100,7 +100,7 @@ - (void)setMaxValue:(float)value { } - (void)setCurrentValue:(float)value { - if (!self->_isDragging) { + if (!_isDragging) { [self.slider setValue:value animated:YES]; } self.preTimeLabel.text = [self.class timeformatFromSeconds:value]; @@ -109,7 +109,8 @@ - (void)setCurrentValue:(float)value { #pragma mark - tool + (NSString *)timeformatFromSeconds:(NSInteger)seconds { - return seconds > 3600 ? [NSString stringWithFormat:@"%02ld:%02ld:%02ld", seconds / 3600, (seconds % 3600) / 60, seconds % 60] : [NSString stringWithFormat:@"%02ld:%02ld", (seconds % 3600) / 60, seconds % 60]; + NSInteger hour = seconds / 3600, min = (seconds % 3600) / 60, sec = seconds % 60; + return seconds > 3600 ? [NSString stringWithFormat:@"%02ld:%02ld:%02ld", (long)hour, (long)min, (long)sec] : [NSString stringWithFormat:@"%02ld:%02ld", (long)min, (long)sec]; } #pragma mark - touch event @@ -135,7 +136,7 @@ - (void)respondsToSliderTouchFinished:(UISlider *)slider { } - (void)respondsToSliderTouchDown:(UISlider *)slider { - self->_isDragging = YES; + _isDragging = YES; slider.userInteractionEnabled = NO; } diff --git a/YBImageBrowser/VideoBrowse/YBVideoBrowseCell.m b/YBImageBrowser/VideoBrowse/YBVideoBrowseCell.m index 92d5091..33790ec 100644 --- a/YBImageBrowser/VideoBrowse/YBVideoBrowseCell.m +++ b/YBImageBrowser/VideoBrowse/YBVideoBrowseCell.m @@ -90,27 +90,27 @@ - (void)prepareForReuse { - (void)willMoveToWindow:(UIWindow *)newWindow { [super willMoveToWindow:newWindow]; - self->_outTransitioning = NO; + _outTransitioning = NO; } - (void)initVars { - self->_layoutDirection = YBImageBrowserLayoutDirectionUnknown; - self->_containerSize = CGSizeMake(1, 1); - self->_playing = NO; - self->_currentIndexIsSelf = NO; - self->_bodyInCenter = YES; - self->_gestureInteractionStartPoint = CGPointZero; - self->_gestureInteracting = NO; - self->_active = YES; - self->_outTransitioning = NO; + _layoutDirection = YBImageBrowserLayoutDirectionUnknown; + _containerSize = CGSizeMake(1, 1); + _playing = NO; + _currentIndexIsSelf = NO; + _bodyInCenter = YES; + _gestureInteractionStartPoint = CGPointZero; + _gestureInteracting = NO; + _active = YES; + _outTransitioning = NO; } #pragma mark - - (void)yb_initializeBrowserCellWithData:(id)data layoutDirection:(YBImageBrowserLayoutDirection)layoutDirection containerSize:(CGSize)containerSize { - self->_containerSize = containerSize; - self->_layoutDirection = layoutDirection; - self->_currentIndexIsSelf = YES; + _containerSize = containerSize; + _layoutDirection = layoutDirection; + _currentIndexIsSelf = YES; if (![data isKindOfClass:YBVideoBrowseCellData.class]) return; self.cellData = data; @@ -121,10 +121,10 @@ - (void)yb_initializeBrowserCellWithData:(id)dat } - (void)yb_browserLayoutDirectionChanged:(YBImageBrowserLayoutDirection)layoutDirection containerSize:(CGSize)containerSize { - self->_containerSize = containerSize; - self->_layoutDirection = layoutDirection; + _containerSize = containerSize; + _layoutDirection = layoutDirection; - if (self->_gestureInteracting) { + if (_gestureInteracting) { [self restoreGestureInteractionWithDuration:0]; } @@ -133,15 +133,15 @@ - (void)yb_browserLayoutDirectionChanged:(YBImageBrowserLayoutDirection)layoutDi - (void)yb_browserPageIndexChanged:(NSUInteger)pageIndex ownIndex:(NSUInteger)ownIndex { if (pageIndex != ownIndex) { - if (self->_playing) { + if (_playing) { [self.baseView yb_hideProgressView]; [self cancelPlay]; [self.cellData loadData]; } [self restoreGestureInteractionWithDuration:0]; - self->_currentIndexIsSelf = NO; + _currentIndexIsSelf = NO; } else { - self->_currentIndexIsSelf = YES; + _currentIndexIsSelf = YES; [self autoPlay]; } } @@ -153,9 +153,9 @@ - (void)yb_browserInitializeFirst:(BOOL)isFirst { } - (void)yb_browserBodyIsInTheCenter:(BOOL)isIn { - self->_bodyInCenter = isIn; + _bodyInCenter = isIn; if (!isIn) { - self->_gestureInteractionStartPoint = CGPointZero; + _gestureInteractionStartPoint = CGPointZero; } } @@ -169,11 +169,11 @@ - (UIView *)yb_browserCurrentForegroundView { } - (void)yb_browserSetGestureInteractionProfile:(YBIBGestureInteractionProfile *)giProfile { - self->_giProfile = giProfile; + _giProfile = giProfile; } - (void)yb_browserStatusBarOrientationBefore:(UIInterfaceOrientation)orientation { - self->_statusBarOrientationBefore = orientation; + _statusBarOrientationBefore = orientation; } #pragma mark - @@ -185,15 +185,15 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecogni #pragma mark - - (void)yb_videoBrowseActionBar:(YBVideoBrowseActionBar *)actionBar clickPlayButton:(UIButton *)playButton { - if (self->_player) { - [self->_player play]; + if (_player) { + [_player play]; [self.actionBar play]; } } - (void)yb_videoBrowseActionBar:(YBVideoBrowseActionBar *)actionBar clickPauseButton:(UIButton *)pauseButton { - if (self->_player) { - [self->_player pause]; + if (_player) { + [_player pause]; [self.actionBar pause]; } } @@ -211,35 +211,36 @@ - (void)yb_videoBrowseTopBar:(YBVideoBrowseTopBar *)topBar clickCancelButton:(UI #pragma mark - private - (void)browserDismiss { - self->_outTransitioning = YES; + _outTransitioning = YES; [self.contentView yb_hideProgressView]; [self yb_hideProgressView]; self.yb_browserDismissBlock(); + _gestureInteracting = NO; } - (void)updateLayoutWithContainerSize:(CGSize)containerSize { self.baseView.frame = CGRectMake(0, 0, containerSize.width, containerSize.height); self.firstFrameImageView.frame = [self.cellData.class getImageViewFrameWithImageSize:self.cellData.firstFrame.size]; self.playButton.center = self.baseView.center; - if (self->_playerLayer) { - self->_playerLayer.frame = CGRectMake(0, 0, containerSize.width, containerSize.height); + if (_playerLayer) { + _playerLayer.frame = CGRectMake(0, 0, containerSize.width, containerSize.height); } self.actionBar.frame = [self.actionBar getFrameWithContainerSize:containerSize]; self.topBar.frame = [self.topBar getFrameWithContainerSize:containerSize]; } - (void)startPlay { - if (!self.cellData.avAsset || self->_playing) return; + if (!self.cellData.avAsset || _playing) return; [self cancelPlay]; - self->_playing = YES; + _playing = YES; - self->_playerItem = [AVPlayerItem playerItemWithAsset:self.cellData.avAsset]; - self->_player = [AVPlayer playerWithPlayerItem:self->_playerItem]; - self->_playerLayer = [AVPlayerLayer playerLayerWithPlayer:self->_player]; - self->_playerLayer.frame = CGRectMake(0, 0, self->_containerSize.width, self->_containerSize.height); - [self.baseView.layer addSublayer:self->_playerLayer]; + _playerItem = [AVPlayerItem playerItemWithAsset:self.cellData.avAsset]; + _player = [AVPlayer playerWithPlayerItem:_playerItem]; + _playerLayer = [AVPlayerLayer playerLayerWithPlayer:_player]; + _playerLayer.frame = CGRectMake(0, 0, _containerSize.width, _containerSize.height); + [self.baseView.layer addSublayer:_playerLayer]; [self addObserverForPlayer]; @@ -255,22 +256,22 @@ - (void)cancelPlay { } - (void)restorePlay { - if (self->_actionBar) self.actionBar.hidden = YES; - if (self->_topBar) self.topBar.hidden = YES; + if (_actionBar) self.actionBar.hidden = YES; + if (_topBar) self.topBar.hidden = YES; [self removeObserverForPlayer]; - if (self->_player) { - [self->_player pause]; - self->_player = nil; + if (_player) { + [_player pause]; + _player = nil; } - if (self->_playerLayer) { - [self->_playerLayer removeFromSuperlayer]; - self->_playerLayer = nil; + if (_playerLayer) { + [_playerLayer removeFromSuperlayer]; + _playerLayer = nil; } - self->_playerItem = nil; + _playerItem = nil; - self->_playing = NO; + _playing = NO; } - (void)restoreAsset { @@ -295,9 +296,9 @@ - (void)autoPlay { } - (void)videoJumpWithScale:(float)scale { - CMTime startTime = CMTimeMakeWithSeconds(scale, self->_player.currentTime.timescale); - AVPlayer *tmpPlayer = self->_player; - [self->_player seekToTime:startTime toleranceBefore:CMTimeMake(1, 1000) toleranceAfter:CMTimeMake(1, 1000) completionHandler:^(BOOL finished) { + CMTime startTime = CMTimeMakeWithSeconds(scale, _player.currentTime.timescale); + AVPlayer *tmpPlayer = _player; + [_player seekToTime:startTime toleranceBefore:CMTimeMake(1, 1000) toleranceAfter:CMTimeMake(1, 1000) completionHandler:^(BOOL finished) { if (finished && tmpPlayer == self->_player) { [self->_player play]; [self.actionBar play]; @@ -370,13 +371,13 @@ - (void)cellDataStateChanged { } - (void)avPlayerItemStatusChanged { - if (!self->_active) return; + if (!_active) return; self.playButton.hidden = YES; - switch (self->_playerItem.status) { + switch (_playerItem.status) { case AVPlayerItemStatusReadyToPlay: { - [self->_player play]; + [_player play]; [self.baseView addSubview:self.actionBar]; [self.baseView addSubview:self.topBar]; @@ -385,7 +386,7 @@ - (void)avPlayerItemStatusChanged { self.yb_browserToolBarHiddenBlock(YES); [self.actionBar play]; - double max = CMTimeGetSeconds(self->_playerItem.duration); + double max = CMTimeGetSeconds(_playerItem.duration); [self.actionBar setMaxValue:isnan(max) || isinf(max) ? 0 : max]; [self.baseView yb_hideProgressView]; @@ -407,20 +408,20 @@ - (void)avPlayerItemStatusChanged { #pragma mark - observe - (void)addObserverForPlayer { - [self->_playerItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil]; + [_playerItem addObserver:self forKeyPath:@"status" options:NSKeyValueObservingOptionNew context:nil]; __weak typeof(self) wSelf = self; - [self->_player addPeriodicTimeObserverForInterval:CMTimeMake(1, 1) queue:dispatch_get_main_queue() usingBlock:^(CMTime time) { + [_player addPeriodicTimeObserverForInterval:CMTimeMake(1, 1) queue:dispatch_get_main_queue() usingBlock:^(CMTime time) { __strong typeof(wSelf) sSelf = wSelf; if (!sSelf) return; float currentTime = time.value / time.timescale; [sSelf.actionBar setCurrentValue:currentTime]; }]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlayFinish:) name:AVPlayerItemDidPlayToEndTimeNotification object:self->_playerItem]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlayFinish:) name:AVPlayerItemDidPlayToEndTimeNotification object:_playerItem]; } - (void)removeObserverForPlayer { - [self->_playerItem removeObserver:self forKeyPath:@"status"]; - [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:self->_playerItem]; + [_playerItem removeObserver:self forKeyPath:@"status"]; + [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:_playerItem]; } - (void)addObserverForDataState { @@ -435,12 +436,12 @@ - (void)removeObserverForDataState { } - (void)videoPlayFinish:(NSNotification *)noti { - if (noti.object == self->_playerItem) { + if (noti.object == _playerItem) { YBVideoBrowseCellData *data = self.cellData; if (data.repeatPlayCount > 0) { --data.repeatPlayCount; [self videoJumpWithScale:0]; - [self->_player play]; + [_player play]; } else { [self cancelPlay]; [self.cellData loadData]; @@ -449,8 +450,8 @@ - (void)videoPlayFinish:(NSNotification *)noti { } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{ - if (!self->_outTransitioning) { - if (object == self->_playerItem) { + if (!_outTransitioning) { + if (object == _playerItem) { if ([keyPath isEqualToString:@"status"]) { [self avPlayerItemStatusChanged]; } @@ -480,21 +481,21 @@ - (void)addObserverForSystem { } - (void)applicationWillResignActive:(NSNotification *)notification { - self->_active = NO; - if (self->_player && self->_playing) { - [self->_player pause]; + _active = NO; + if (_player && _playing) { + [_player pause]; [self.actionBar pause]; } } - (void)applicationDidBecomeActive:(NSNotification *)notification { - self->_active = YES; + _active = YES; } - (void)didChangeStatusBarFrame { if ([UIApplication sharedApplication].statusBarFrame.size.height > YBIB_HEIGHT_STATUSBAR) { - if (self->_player && self->_playing) { - [self->_player pause]; + if (_player && _playing) { + [_player pause]; [self.actionBar pause]; } } @@ -507,8 +508,8 @@ - (void)audioRouteChangeListenerCallback:(NSNotification*)notification { case AVAudioSessionRouteChangeReasonNewDeviceAvailable: break; case AVAudioSessionRouteChangeReasonOldDeviceUnavailable: - if (self->_player && self->_playing) { -// [self->_player pause]; + if (_player && _playing) { + [_player pause]; [self.actionBar pause]; } break; @@ -524,13 +525,15 @@ - (void)addGesture { UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(respondsToPanGesture:)]; panGesture.cancelsTouchesInView = NO; panGesture.delegate = self; + [tapGesture requireGestureRecognizerToFail:panGesture]; + [self.baseView addGestureRecognizer:tapGesture]; [self.baseView addGestureRecognizer:panGesture]; } - (void)respondsToTapGesture:(UITapGestureRecognizer *)tap { - if (self->_playing) { + if (_playing) { self.actionBar.hidden = !self.actionBar.isHidden; self.topBar.hidden = !self.topBar.isHidden; } else { @@ -539,47 +542,47 @@ - (void)respondsToTapGesture:(UITapGestureRecognizer *)tap { } - (void)respondsToPanGesture:(UIPanGestureRecognizer *)pan { - if ((!self.firstFrameImageView.image && !self->_playing) || self->_giProfile.disable) return; + if ((!self.firstFrameImageView.image && !_playing) || _giProfile.disable) return; CGPoint point = [pan locationInView:self]; if (pan.state == UIGestureRecognizerStateBegan) { - self->_gestureInteractionStartPoint = point; + _gestureInteractionStartPoint = point; } else if (pan.state == UIGestureRecognizerStateCancelled || pan.state == UIGestureRecognizerStateEnded || pan.state == UIGestureRecognizerStateRecognized || pan.state == UIGestureRecognizerStateFailed) { // END - if (self->_gestureInteracting) { + if (_gestureInteracting) { CGPoint velocity = [pan velocityInView:self.baseView]; - BOOL velocityArrive = ABS(velocity.y) > self->_giProfile.dismissVelocityY; - BOOL distanceArrive = ABS(point.y - self->_gestureInteractionStartPoint.y) > self->_containerSize.height * self->_giProfile.dismissScale; + BOOL velocityArrive = ABS(velocity.y) > _giProfile.dismissVelocityY; + BOOL distanceArrive = ABS(point.y - _gestureInteractionStartPoint.y) > _containerSize.height * _giProfile.dismissScale; BOOL shouldDismiss = distanceArrive || velocityArrive; if (shouldDismiss) { [self browserDismiss]; } else { - [self restoreGestureInteractionWithDuration:self->_giProfile.restoreDuration]; + [self restoreGestureInteractionWithDuration:_giProfile.restoreDuration]; } } } else if (pan.state == UIGestureRecognizerStateChanged) { CGPoint velocityPoint = [pan velocityInView:self.baseView]; - CGFloat triggerDistance = self->_giProfile.triggerDistance; + CGFloat triggerDistance = _giProfile.triggerDistance; - BOOL distanceArrive = ABS(point.y - self->_gestureInteractionStartPoint.y) > triggerDistance && (ABS(point.x - self->_gestureInteractionStartPoint.x) < triggerDistance && ABS(velocityPoint.x) < 500); + BOOL distanceArrive = ABS(point.y - _gestureInteractionStartPoint.y) > triggerDistance && (ABS(point.x - _gestureInteractionStartPoint.x) < triggerDistance && ABS(velocityPoint.x) < 500); - BOOL shouldStart = !self->_gestureInteracting && distanceArrive && self->_currentIndexIsSelf && self->_bodyInCenter; + BOOL shouldStart = !_gestureInteracting && distanceArrive && _currentIndexIsSelf && _bodyInCenter; // START if (shouldStart) { - if (self->_actionBar) self.actionBar.hidden = YES; - if (self->_topBar) self.topBar.hidden = YES; + if (_actionBar) self.actionBar.hidden = YES; + if (_topBar) self.topBar.hidden = YES; - if ([UIApplication sharedApplication].statusBarOrientation != self->_statusBarOrientationBefore) { + if ([UIApplication sharedApplication].statusBarOrientation != _statusBarOrientationBefore) { [self browserDismiss]; } else { - self->_gestureInteractionStartPoint = point; + _gestureInteractionStartPoint = point; CGRect startFrame = self.baseView.bounds; CGFloat anchorX = (point.x - startFrame.origin.x) / startFrame.size.width, @@ -590,19 +593,19 @@ - (void)respondsToPanGesture:(UIPanGestureRecognizer *)pan { self.yb_browserScrollEnabledBlock(NO); self.yb_browserToolBarHiddenBlock(YES); - self->_gestureInteracting = YES; + _gestureInteracting = YES; } } // CHANGE - if (self->_gestureInteracting) { + if (_gestureInteracting) { self.baseView.center = point; - CGFloat scale = 1 - ABS(point.y - self->_gestureInteractionStartPoint.y) / (self->_containerSize.height * 1.2); + CGFloat scale = 1 - ABS(point.y - _gestureInteractionStartPoint.y) / (_containerSize.height * 1.2); if (scale > 1) scale = 1; if (scale < 0.35) scale = 0.35; self.baseView.transform = CGAffineTransformMakeScale(scale, scale); - CGFloat alpha = 1 - ABS(point.y - self->_gestureInteractionStartPoint.y) / (self->_containerSize.height * 1.1); + CGFloat alpha = 1 - ABS(point.y - _gestureInteractionStartPoint.y) / (_containerSize.height * 1.1); if (alpha > 1) alpha = 1; if (alpha < 0) alpha = 0; self.yb_browserChangeAlphaBlock(alpha, 0); @@ -611,8 +614,8 @@ - (void)respondsToPanGesture:(UIPanGestureRecognizer *)pan { } - (void)restoreGestureInteractionWithDuration:(NSTimeInterval)duration { - if (self->_actionBar) self.actionBar.hidden = NO; - if (self->_topBar) self.topBar.hidden = NO; + if (_actionBar) self.actionBar.hidden = NO; + if (_topBar) self.topBar.hidden = NO; self.yb_browserChangeAlphaBlock(1, duration); diff --git a/YBImageBrowser/VideoBrowse/YBVideoBrowseCellData.m b/YBImageBrowser/VideoBrowse/YBVideoBrowseCellData.m index 01e5c9f..5926cd0 100644 --- a/YBImageBrowser/VideoBrowse/YBVideoBrowseCellData.m +++ b/YBImageBrowser/VideoBrowse/YBVideoBrowseCellData.m @@ -36,12 +36,12 @@ - (instancetype)init { } - (void)initVars { - self->_autoPlayCount = 0; - self->_allowSaveToPhotoAlbum = YES; - self->_allowShowSheetView = YES; - self->_dataState = YBVideoBrowseCellDataStateInvalid; - self->_dataDownloadState = YBVideoBrowseCellDataDownloadStateNone; - self->_loading = NO; + _autoPlayCount = 0; + _allowSaveToPhotoAlbum = YES; + _allowShowSheetView = YES; + _dataState = YBVideoBrowseCellDataStateInvalid; + _dataDownloadState = YBVideoBrowseCellDataDownloadStateNone; + _loading = NO; } #pragma mark - @@ -204,8 +204,8 @@ - (void)downloadWithUrl:(NSURL *)url { NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration]; NSURLSession *session = [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:[NSOperationQueue mainQueue]]; - self->_downloadTask = [session downloadTaskWithURL:url]; - [self->_downloadTask resume]; + _downloadTask = [session downloadTaskWithURL:url]; + [_downloadTask resume]; } #pragma mark - @@ -255,7 +255,7 @@ - (void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error co - (void)setUrl:(NSURL *)url { _url = [url isKindOfClass:NSString.class] ? [NSURL URLWithString:(NSString *)url] : url; - self.avAsset = [AVURLAsset URLAssetWithURL:self->_url options:nil]; + self.avAsset = [AVURLAsset URLAssetWithURL:_url options:nil]; } @end diff --git a/YBImageBrowser/YBImageBrowser.h b/YBImageBrowser/YBImageBrowser.h index f93d762..741802a 100644 --- a/YBImageBrowser/YBImageBrowser.h +++ b/YBImageBrowser/YBImageBrowser.h @@ -70,7 +70,7 @@ typedef NS_ENUM(NSInteger, YBImageBrowserTransitionType) { */ - (id)currentData; -/** The default is YES. */ +/** The default is YES. (The default is NO which low memory device.) */ @property (nonatomic, assign) BOOL shouldPreload; @@ -119,7 +119,8 @@ typedef NS_ENUM(NSInteger, YBImageBrowserTransitionType) { /** The default is YES. */ @property (nonatomic, assign) BOOL shouldHideStatusBar; -/** The number of data cache limits, the default is 6. It is effective when using the proxy to configure data sources. If the data cache is overmuch, may lead to excessive memory consumption. */ +/** The number of data cache limits, the default is 8. (The default is 1 which low memory device.) + It is effective when using the proxy to configure data sources. If the data cache is overmuch, may lead to excessive memory consumption. */ @property (nonatomic, assign) NSUInteger dataCacheCountLimit; @end diff --git a/YBImageBrowser/YBImageBrowser.m b/YBImageBrowser/YBImageBrowser.m index 7b6af5c..6cbf4ce 100644 --- a/YBImageBrowser/YBImageBrowser.m +++ b/YBImageBrowser/YBImageBrowser.m @@ -54,35 +54,41 @@ - (instancetype)init { } - (void)initVars { - self->_isFirstViewDidAppear = NO; - self->_isRestoringDeviceOrientation = NO; + _isFirstViewDidAppear = NO; + _isRestoringDeviceOrientation = NO; - self->_currentIndex = 0; - self->_supportedOrientations = UIInterfaceOrientationMaskAllButUpsideDown; - self->_backgroundColor = [UIColor blackColor]; - self->_enterTransitionType = YBImageBrowserTransitionTypeCoherent; - self->_outTransitionType = YBImageBrowserTransitionTypeCoherent; - self->_transitionDuration = 0.25; - self->_autoHideSourceObject = YES; + _currentIndex = 0; + _supportedOrientations = UIInterfaceOrientationMaskAllButUpsideDown; + _backgroundColor = [UIColor blackColor]; + _enterTransitionType = YBImageBrowserTransitionTypeCoherent; + _outTransitionType = YBImageBrowserTransitionTypeCoherent; + _transitionDuration = 0.25; + _autoHideSourceObject = YES; - self.shouldPreload = YES; + if (YBIBLowMemory()) { + self.shouldPreload = NO; + self.dataCacheCountLimit = 1; + } else { + self.shouldPreload = YES; + self.dataCacheCountLimit = 8; + } YBImageBrowserToolBar *toolBar = [YBImageBrowserToolBar new]; - self->_defaultToolBar = toolBar; - self->_toolBars = @[toolBar]; + _defaultToolBar = toolBar; + _toolBars = @[toolBar]; YBImageBrowserSheetView *sheetView = [YBImageBrowserSheetView new]; YBImageBrowserSheetAction *saveAction = [YBImageBrowserSheetAction actionWithName:[YBIBCopywriter shareCopywriter].saveToPhotoAlbum identity:kYBImageBrowserSheetActionIdentitySaveToPhotoAlbum action:nil]; sheetView.actions = @[saveAction]; - self->_defaultSheetView = sheetView; - self->_sheetView = sheetView; + _defaultSheetView = sheetView; + _sheetView = sheetView; - self->_shouldHideStatusBar = YES; + _shouldHideStatusBar = YES; } - (void)viewDidLoad { [super viewDidLoad]; - self.view.backgroundColor = self->_backgroundColor; + self.view.backgroundColor = _backgroundColor; [self addGesture]; } @@ -93,18 +99,18 @@ - (void)viewWillAppear:(BOOL)animated { - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; - self->_windowLevelByDefault = self.view.window.windowLevel; + _windowLevelByDefault = self.view.window.windowLevel; [self setStatusBarHide:YES]; - if (!self->_isFirstViewDidAppear) { + if (!_isFirstViewDidAppear) { [self updateLayoutOfSubViewsWithLayoutDirection:[YBIBLayoutDirectionManager getLayoutDirectionByStatusBar]]; - [self.browserView scrollToPageWithIndex:self->_currentIndex]; + [self.browserView scrollToPageWithIndex:_currentIndex]; [self addSubViews]; - self->_isFirstViewDidAppear = YES; + _isFirstViewDidAppear = YES; [self addObserverForSystem]; } @@ -145,7 +151,7 @@ - (void)respondsToLongPress:(UILongPressGestureRecognizer *)sender { if (self.sheetView && (![[self currentData] respondsToSelector:@selector(yb_browserAllowShowSheetView)] || [[self currentData] yb_browserAllowShowSheetView])) { [self.view addSubview:self.sheetView]; - [self.sheetView yb_browserShowSheetViewWithData:[self currentData] layoutDirection:self->_layoutDirection containerSize:self->_containerSize]; + [self.sheetView yb_browserShowSheetViewWithData:[self currentData] layoutDirection:_layoutDirection containerSize:_containerSize]; } } } @@ -162,7 +168,7 @@ - (void)addObserverForSystem { - (void)didChangeStatusBarFrame { if ([UIApplication sharedApplication].statusBarFrame.size.height > YBIB_HEIGHT_STATUSBAR) { - self.view.frame = CGRectMake(0, 0, self->_containerSize.width, self->_containerSize.height); + self.view.frame = CGRectMake(0, 0, _containerSize.width, _containerSize.height); } } @@ -175,10 +181,10 @@ - (void)addSubViews { if ([obj respondsToSelector:@selector(setYb_browserShowSheetViewBlock:)]) { __weak typeof(self) wSelf = self; [obj setYb_browserShowSheetViewBlock:^(id _Nonnull data) { - __strong typeof(wSelf) sSelf = wSelf; - if (sSelf.sheetView) { - [sSelf.view addSubview:sSelf.sheetView]; - [sSelf.sheetView yb_browserShowSheetViewWithData:data layoutDirection:sSelf->_layoutDirection containerSize:sSelf->_containerSize]; + __strong typeof(wSelf) self = wSelf; + if (self.sheetView) { + [self.view addSubview:self.sheetView]; + [self.sheetView yb_browserShowSheetViewWithData:data layoutDirection:self->_layoutDirection containerSize:self->_containerSize]; } }]; } @@ -186,9 +192,9 @@ - (void)addSubViews { } - (void)updateLayoutOfSubViewsWithLayoutDirection:(YBImageBrowserLayoutDirection)layoutDirection { - self->_layoutDirection = layoutDirection; + _layoutDirection = layoutDirection; CGSize containerSize = layoutDirection == YBImageBrowserLayoutDirectionHorizontal ? CGSizeMake(YBIMAGEBROWSER_HEIGHT, YBIMAGEBROWSER_WIDTH) : CGSizeMake(YBIMAGEBROWSER_WIDTH, YBIMAGEBROWSER_HEIGHT); - self->_containerSize = containerSize; + _containerSize = containerSize; if (self.sheetView && self.sheetView.superview) { [self.sheetView yb_browserHideSheetViewWithAnimation:NO]; @@ -201,7 +207,7 @@ - (void)updateLayoutOfSubViewsWithLayoutDirection:(YBImageBrowserLayoutDirection } - (void)pageIndexChanged:(NSUInteger)index { - self->_currentIndex = index; + _currentIndex = index; id data = [self currentData]; @@ -250,7 +256,7 @@ - (void)setCurrentIndex:(NSUInteger)currentIndex { - (void)reloadData { [self.browserView yb_reloadData]; - [self.browserView scrollToPageWithIndex:self->_currentIndex]; + [self.browserView scrollToPageWithIndex:_currentIndex]; [self pageIndexChanged:self.browserView.currentIndex]; } @@ -279,8 +285,8 @@ - (void)showFromController:(UIViewController *)fromController { } } - self->_statusBarOrientationBefore = [UIApplication sharedApplication].statusBarOrientation; - self.browserView.statusBarOrientationBefore = self->_statusBarOrientationBefore; + _statusBarOrientationBefore = [UIApplication sharedApplication].statusBarOrientation; + self.browserView.statusBarOrientationBefore = _statusBarOrientationBefore; [fromController presentViewController:self animated:YES completion:nil]; } @@ -316,7 +322,7 @@ - (void)setShouldPreload:(BOOL)shouldPreload { #pragma mark - internal - (void)setHiddenSourceObject:(id)hiddenSourceObject { - if (!self->_autoHideSourceObject) return; + if (!_autoHideSourceObject) return; if (_hiddenSourceObject && [_hiddenSourceObject respondsToSelector:@selector(setHidden:)]) { [_hiddenSourceObject setValue:@(NO) forKey:@"hidden"]; } @@ -343,14 +349,14 @@ - (void)yb_imageBrowserViewDismiss:(YBImageBrowserView *)browserView { obj.hidden = YES; }]; - if ([UIApplication sharedApplication].statusBarOrientation != self->_statusBarOrientationBefore && [[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) { + if ([UIApplication sharedApplication].statusBarOrientation != _statusBarOrientationBefore && [[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)]) { SEL selector = NSSelectorFromString(@"setOrientation:"); NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]]; [invocation setSelector:selector]; [invocation setTarget:[UIDevice currentDevice]]; - NSInteger val = self->_statusBarOrientationBefore; + NSInteger val = _statusBarOrientationBefore; [invocation setArgument:&val atIndex:2]; - self->_isRestoringDeviceOrientation = YES; + _isRestoringDeviceOrientation = YES; [invocation invoke]; } @@ -413,10 +419,10 @@ - (YBIBLayoutDirectionManager *)layoutDirectionManager { _layoutDirectionManager = [YBIBLayoutDirectionManager new]; __weak typeof(self) wSelf = self; [_layoutDirectionManager setLayoutDirectionChangedBlock:^(YBImageBrowserLayoutDirection layoutDirection) { - __strong typeof(self) sSelf = wSelf; - if (layoutDirection == YBImageBrowserLayoutDirectionUnknown || sSelf.transitionManager.transitioning || sSelf->_isRestoringDeviceOrientation) return; + __strong typeof(wSelf) self = wSelf; + if (layoutDirection == YBImageBrowserLayoutDirectionUnknown || self.transitionManager.transitioning || self->_isRestoringDeviceOrientation) return; - [sSelf updateLayoutOfSubViewsWithLayoutDirection:layoutDirection]; + [self updateLayoutOfSubViewsWithLayoutDirection:layoutDirection]; }]; } return _layoutDirectionManager; diff --git a/YBImageBrowserDemo.xcodeproj/project.pbxproj b/YBImageBrowserDemo.xcodeproj/project.pbxproj index 70f4ed1..3cec1db 100644 --- a/YBImageBrowserDemo.xcodeproj/project.pbxproj +++ b/YBImageBrowserDemo.xcodeproj/project.pbxproj @@ -402,7 +402,7 @@ 706BF133207CAAB20034663E /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0920; + LastUpgradeCheck = 1020; ORGANIZATIONNAME = "杨波"; TargetAttributes = { 706BF13A207CAAB30034663E = { @@ -565,6 +565,7 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -572,6 +573,7 @@ CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -620,6 +622,7 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; CLANG_WARN_EMPTY_BODY = YES; @@ -627,6 +630,7 @@ CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; diff --git a/YBImageBrowserDemo/UseCase/MainViewController.m b/YBImageBrowserDemo/UseCase/MainViewController.m index 70110ed..b4e0fc3 100644 --- a/YBImageBrowserDemo/UseCase/MainViewController.m +++ b/YBImageBrowserDemo/UseCase/MainViewController.m @@ -206,7 +206,7 @@ - (void)clickSegmentControl:(UISegmentedControl *)sender { case 1: { self.dataArray = @[@"localImage0.jpeg", @"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1524118914981&di=7fa3504d8767ab709c4fb519ad67cf09&imgtype=0&src=http%3A%2F%2Fimg5.duitang.com%2Fuploads%2Fitem%2F201410%2F05%2F20141005221124_awAhx.jpeg", - @"localBigImage1.jpg", + @"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1524118984884&di=7c73ddf9d321ef94a19567337628580b&imgtype=0&src=http%3A%2F%2Fimg5q.duitang.com%2Fuploads%2Fitem%2F201506%2F07%2F20150607185100_XQvYT.jpeg", @"video0.MP4", @"https://aweme.snssdk.com/aweme/v1/playwm/?video_id=v0200ff00000bdkpfpdd2r6fb5kf6m50&line=0.MP4", @"localGifImage0.gif",