From 011c70493161b865e21c84e9e46bb6847a358f83 Mon Sep 17 00:00:00 2001 From: Sergey Demchenko Date: Tue, 8 Nov 2016 21:29:41 -0800 Subject: [PATCH 01/10] Update MWPhotoBrowser.h --- Pod/Classes/MWPhotoBrowser.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Pod/Classes/MWPhotoBrowser.h b/Pod/Classes/MWPhotoBrowser.h index 4225f9cc1..82a4a0722 100644 --- a/Pod/Classes/MWPhotoBrowser.h +++ b/Pod/Classes/MWPhotoBrowser.h @@ -38,9 +38,18 @@ @end +@protocol MWProfilePhotosLikeActions + +- (NSUInteger)likesCount:(NSInteger)photoIndex; +- (BOOL)isLiked:(NSInteger)photoIndex; +- (void)likePhoto:(NSInteger)photoIndex like:(BOOL)like; + +@end + @interface MWPhotoBrowser : UIViewController @property (nonatomic, weak) IBOutlet id delegate; +@property (nonatomic, weak) id fullscreenPhotoDelegate; @property (nonatomic) BOOL zoomPhotosToFill; @property (nonatomic) BOOL displayNavArrows; @property (nonatomic) BOOL displayActionButton; @@ -72,4 +81,6 @@ - (void)showNextPhotoAnimated:(BOOL)animated; - (void)showPreviousPhotoAnimated:(BOOL)animated; +- (void)update; + @end From 69c44e6c71f5e9e615f4d6c8578c59544a4ed143 Mon Sep 17 00:00:00 2001 From: Sergey Demchenko Date: Tue, 8 Nov 2016 21:30:15 -0800 Subject: [PATCH 02/10] Update MWPhotoBrowser.m --- Pod/Classes/MWPhotoBrowser.m | 110 +++++++++++++++++++++++++++++++++-- 1 file changed, 104 insertions(+), 6 deletions(-) diff --git a/Pod/Classes/MWPhotoBrowser.m b/Pod/Classes/MWPhotoBrowser.m index 0de7faaab..f137723e6 100644 --- a/Pod/Classes/MWPhotoBrowser.m +++ b/Pod/Classes/MWPhotoBrowser.m @@ -158,6 +158,28 @@ - (void)viewDidLoad { _pagingScrollView.backgroundColor = [UIColor blackColor]; _pagingScrollView.contentSize = [self contentSizeForPagingScrollView]; [self.view addSubview:_pagingScrollView]; + + //Setup likes container under scroll view + CGRect likesContainerRect = [self frameForLikesContainer]; + _likesContainer = [[UIView alloc] initWithFrame:likesContainerRect]; + _likesContainer.backgroundColor = [UIColor clearColor]; + [self.view addSubview:_likesContainer]; + + // Setup like button + CGRect likesButtonRect = [self frameForLikeButton]; + _likesButton = [[UIButton alloc] initWithFrame:likesButtonRect]; + [_likesButton setImage:[UIImage imageNamed:@"like_unselected"] forState:UIControlStateNormal]; + [_likesButton setImage:[UIImage imageNamed:@"like_selected"] forState:UIControlStateSelected]; + [_likesButton addTarget:self action:@selector(likeButtonPressed) forControlEvents:UIControlEventTouchUpInside]; + [_likesContainer addSubview:_likesButton]; + + // Setup like label + CGRect likesLabelRect = [self frameForLikesLabel]; + _likesLabel = [[UILabel alloc] initWithFrame:likesLabelRect]; + _likesLabel.textColor = [UIColor colorWithRed:172.0/255.0 green:172.0/255.0 blue:172.0/255.0 alpha:1]; + _likesLabel.numberOfLines = 1; + [_likesContainer addSubview:_likesLabel]; + // Toolbar _toolbar = [[UIToolbar alloc] initWithFrame:[self frameForToolbarAtOrientation:self.interfaceOrientation]]; @@ -177,7 +199,8 @@ - (void)viewDidLoad { _nextButton = [[UIBarButtonItem alloc] initWithImage:nextButtonImage style:UIBarButtonItemStylePlain target:self action:@selector(gotoNextPage)]; } if (self.displayActionButton) { - _actionButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(actionButtonPressed:)]; + UIImage *imageForButton = [UIImage imageNamed:@"three_dots"]; + _actionButton = [[UIBarButtonItem alloc] initWithImage:imageForButton style:UIBarButtonItemStylePlain target:self action:@selector(actionButtonPressed:)]; } // Update @@ -219,6 +242,7 @@ - (void)performLayout { self.navigationItem.rightBarButtonItem = _doneButton; } else { // We're not first so show back button + UIViewController *previousViewController = [self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-2]; NSString *backButtonTitle = previousViewController.navigationItem.backBarButtonItem ? previousViewController.navigationItem.backBarButtonItem.title : previousViewController.title; UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle:backButtonTitle style:UIBarButtonItemStylePlain target:nil action:nil]; @@ -299,6 +323,9 @@ - (void)performLayout { - (void)viewDidUnload { _currentPageIndex = 0; _pagingScrollView = nil; + _likesContainer = nil; + _likesLabel = nil; + _likesButton = nil; _visiblePages = nil; _recycledPages = nil; _toolbar = nil; @@ -442,11 +469,16 @@ - (void)didMoveToParentViewController:(UIViewController *)parent { - (void)setNavBarAppearance:(BOOL)animated { [self.navigationController setNavigationBarHidden:NO animated:animated]; UINavigationBar *navBar = self.navigationController.navigationBar; +// navBar.tintColor = [UIColor whiteColor]; +// navBar.barTintColor = nil; navBar.tintColor = [UIColor whiteColor]; - navBar.barTintColor = nil; + navBar.barTintColor = [UIColor clearColor]; navBar.shadowImage = nil; navBar.translucent = YES; navBar.barStyle = UIBarStyleBlackTranslucent; + //UIImage *imageForButton = [UIImage imageForResourcePath:@"MWPhotoBrowser.bundle/back_arrow_white" ofType:@"png" inBundle:[NSBundle bundleForClass:[self class]]]; + UIImage *imageForButton = [UIImage imageNamed:@"back_arrow_white"]; + self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:imageForButton style:UIBarButtonItemStylePlain target:self action:@selector(backButtonPressed:)]; [navBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault]; [navBar setBackgroundImage:nil forBarMetrics:UIBarMetricsLandscapePhone]; } @@ -966,15 +998,69 @@ - (void)didStartViewingPageAtIndex:(NSUInteger)index { // Update nav [self updateNavigation]; + + [self update]; +} + +- (void)update +{ + BOOL likedByMe = [_fullscreenPhotoDelegate isLiked:_currentPageIndex]; + _likesButton.selected = likedByMe; + //Update likes container + NSUInteger *likes = [_fullscreenPhotoDelegate likesCount:_currentPageIndex]; + if (likes > 0) { + NSString *likesWord = likes == 1 ? @"like" : @"likes"; + _likesLabel.text = [NSString stringWithFormat:@"%d %@", likes, likesWord]; + } else { + _likesLabel.text = @"0 likes"; + } } #pragma mark - Frame Calculations - (CGRect)frameForPagingScrollView { - CGRect frame = self.view.bounds;// [[UIScreen mainScreen] bounds]; - frame.origin.x -= PADDING; - frame.size.width += (2 * PADDING); + //FLAG! +// CGRect frame = self.view.bounds;// [[UIScreen mainScreen] bounds]; +// frame.origin.x -= PADDING; +// frame.size.width += (2 * PADDING); + //return CGRectIntegral(frame); + CGRect tabbar = [self frameForToolbarAtOrientation:self.interfaceOrientation]; + CGFloat scrollViewMargin = [UIApplication sharedApplication].statusBarFrame.size.height + tabbar.size.height; + CGFloat posX = 0 - PADDING; + CGFloat posY = scrollViewMargin; + CGFloat width = self.view.frame.size.width + (2 * PADDING); + CGFloat height = self.view.frame.size.height - (2 * scrollViewMargin); + CGRect frame = CGRectMake(posX, posY, width, height); + return CGRectIntegral(frame); +} + +- (CGRect)frameForLikesContainer { + CGFloat containerWidth = 100; + CGFloat containerHeight = 40; + CGRect scrollViewFrame = [self frameForPagingScrollView]; + CGFloat posX = scrollViewFrame.size.width / 2 - containerWidth / 2; + CGFloat posY = scrollViewFrame.origin.y + scrollViewFrame.size.height; + CGRect frame = CGRectMake(posX, posY, containerWidth, containerHeight); + return CGRectIntegral(frame); +} + +- (CGRect)frameForLikeButton { + CGRect parentContainerRect = [self frameForLikesContainer]; + CGFloat buttonSide = parentContainerRect.size.height; + CGFloat posX = 0; + CGFloat posY = 0; + CGRect frame = CGRectMake(posX, posY, buttonSide, buttonSide); + return CGRectIntegral(frame); +} + +- (CGRect)frameForLikesLabel { + CGRect parentContainerRect = [self frameForLikesContainer]; + CGFloat labelHeight = parentContainerRect.size.height; + CGFloat labelWidth = parentContainerRect.size.width - labelHeight; + CGFloat posX = labelHeight; + CGFloat posY = 0; + CGRect frame = CGRectMake(posX, posY, labelWidth, labelHeight); return CGRectIntegral(frame); } @@ -1102,6 +1188,8 @@ - (void)updateNavigation { } else { self.title = nil; } + //HIDE SELF TITLE ANYWAY + self.title = nil; // Buttons _previousButton.enabled = (_currentPageIndex > 0); @@ -1116,7 +1204,7 @@ - (void)updateNavigation { _actionButton.enabled = YES; _actionButton.tintColor = nil; } - + } - (void)jumpToPageAtIndex:(NSUInteger)index animated:(BOOL)animated { @@ -1630,6 +1718,16 @@ - (void)actionButtonPressed:(id)sender { } +- (void)backButtonPressed:(id)sender { + [self.navigationController popViewControllerAnimated:true]; +} + +- (void)likeButtonPressed { + BOOL like = !_likesButton.selected; + [_fullscreenPhotoDelegate likePhoto:_currentPageIndex like:like]; + [_fullscreenPhotoDelegate isLiked:_currentPageIndex]; +} + #pragma mark - Action Progress - (MBProgressHUD *)progressHUD { From 77ed1cac4eb44d3c54c55b7f7342041e477d656a Mon Sep 17 00:00:00 2001 From: Sergey Demchenko Date: Tue, 8 Nov 2016 21:40:32 -0800 Subject: [PATCH 03/10] Update MWPhotoBrowserPrivate.h --- Pod/Classes/MWPhotoBrowserPrivate.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Pod/Classes/MWPhotoBrowserPrivate.h b/Pod/Classes/MWPhotoBrowserPrivate.h index 5770d6787..ff2ff6b9c 100644 --- a/Pod/Classes/MWPhotoBrowserPrivate.h +++ b/Pod/Classes/MWPhotoBrowserPrivate.h @@ -23,6 +23,9 @@ // Views UIScrollView *_pagingScrollView; + UIView *_likesContainer; + UILabel *_likesLabel; + UIButton *_likesButton; // Paging & layout NSMutableSet *_visiblePages, *_recycledPages; From 53fa84bbac920fc19e2725e2738c6ef816a06948 Mon Sep 17 00:00:00 2001 From: Sergey Demchenko Date: Tue, 15 Nov 2016 20:07:37 -0800 Subject: [PATCH 04/10] Update MWZoomingScrollView.m --- Pod/Classes/MWZoomingScrollView.m | 52 +++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/Pod/Classes/MWZoomingScrollView.m b/Pod/Classes/MWZoomingScrollView.m index 75039ffa6..0f8c420be 100644 --- a/Pod/Classes/MWZoomingScrollView.m +++ b/Pod/Classes/MWZoomingScrollView.m @@ -17,7 +17,7 @@ // Private methods and properties @interface MWZoomingScrollView () { - MWPhotoBrowser __weak *_photoBrowser; + //MWPhotoBrowser __weak *_photoBrowser; MWTapDetectingView *_tapView; // for background taps MWTapDetectingImageView *_photoImageView; DACircularProgressView *_loadingIndicator; @@ -49,7 +49,7 @@ - (id)initWithPhotoBrowser:(MWPhotoBrowser *)browser { _photoImageView.contentMode = UIViewContentModeCenter; _photoImageView.backgroundColor = [UIColor blackColor]; [self addSubview:_photoImageView]; - + // Loading indicator _loadingIndicator = [[DACircularProgressView alloc] initWithFrame:CGRectMake(140.0f, 30.0f, 40.0f, 40.0f)]; _loadingIndicator.userInteractionEnabled = NO; @@ -305,6 +305,16 @@ - (void)setMaxMinZoomScalesForCurrentBounds { } +#pragma mark - Frame calculation + +- (CGRect)frameForLikeAnimation:(CGRect)frame { + CGFloat animationContainerSize = 125; + CGFloat posX = (frame.size.width - animationContainerSize) / 2; + CGFloat posY = (frame.size.height - animationContainerSize) / 2; + CGRect frameForRect = CGRectMake(posX, posY, animationContainerSize, animationContainerSize); + return frameForRect; +} + #pragma mark - Layout - (void)layoutSubviews { @@ -409,6 +419,7 @@ - (void)handleDoubleTap:(CGPoint)touchPoint { // Delay controls [_photoBrowser hideControlsAfterDelay]; + } @@ -416,8 +427,33 @@ - (void)handleDoubleTap:(CGPoint)touchPoint { - (void)imageView:(UIImageView *)imageView singleTapDetected:(UITouch *)touch { [self handleSingleTap:[touch locationInView:imageView]]; } + - (void)imageView:(UIImageView *)imageView doubleTapDetected:(UITouch *)touch { - [self handleDoubleTap:[touch locationInView:imageView]]; + UIImageView *likeAnimationView = [[UIImageView alloc] initWithFrame:[self frameForLikeAnimation:self.frame]]; + likeAnimationView.image = [UIImage imageNamed:@"big_heart"]; + likeAnimationView.contentMode = UIViewContentModeScaleAspectFit; + [self addSubview:likeAnimationView]; + + [UIView animateWithDuration:0.1f delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ + likeAnimationView.transform = CGAffineTransformMakeScale(1.3, 1.3); + likeAnimationView.alpha = 1.0; + } completion:^(BOOL finished) { + [UIView animateWithDuration:0.1f delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ + likeAnimationView.transform = CGAffineTransformMakeScale(1.0, 1.0); + } completion:^(BOOL finished) { + [UIView animateWithDuration:0.1f delay:0.3 options:UIViewAnimationOptionAllowUserInteraction animations:^{ + likeAnimationView.transform = CGAffineTransformMakeScale(0.3, 0.3); + likeAnimationView.alpha = 0.0; + } completion:^(BOOL finished) { + likeAnimationView.transform = CGAffineTransformMakeScale(1.0, 1.0); + [likeAnimationView removeFromSuperview]; + }]; + }]; + }]; + + if (![self.photoBrowser.fullscreenPhotoDelegate isLiked:self.photoBrowser.currentPageIndex]){ + [self.photoBrowser likeButtonPressed]; + } } // Background View @@ -431,15 +467,5 @@ - (void)view:(UIView *)view singleTapDetected:(UITouch *)touch { touchY += self.contentOffset.y; [self handleSingleTap:CGPointMake(touchX, touchY)]; } -- (void)view:(UIView *)view doubleTapDetected:(UITouch *)touch { - // Translate touch location to image view location - CGFloat touchX = [touch locationInView:view].x; - CGFloat touchY = [touch locationInView:view].y; - touchX *= 1/self.zoomScale; - touchY *= 1/self.zoomScale; - touchX += self.contentOffset.x; - touchY += self.contentOffset.y; - [self handleDoubleTap:CGPointMake(touchX, touchY)]; -} @end From f7ea3e39fb43583749da2096611fbc28f982d53a Mon Sep 17 00:00:00 2001 From: Sergey Demchenko Date: Tue, 15 Nov 2016 20:08:27 -0800 Subject: [PATCH 05/10] Update MWPhotoBrowser.m --- Pod/Classes/MWPhotoBrowser.m | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Pod/Classes/MWPhotoBrowser.m b/Pod/Classes/MWPhotoBrowser.m index f137723e6..69d4d2705 100644 --- a/Pod/Classes/MWPhotoBrowser.m +++ b/Pod/Classes/MWPhotoBrowser.m @@ -159,7 +159,7 @@ - (void)viewDidLoad { _pagingScrollView.contentSize = [self contentSizeForPagingScrollView]; [self.view addSubview:_pagingScrollView]; - //Setup likes container under scroll view + // Setup likes container under scroll view CGRect likesContainerRect = [self frameForLikesContainer]; _likesContainer = [[UIView alloc] initWithFrame:likesContainerRect]; _likesContainer.backgroundColor = [UIColor clearColor]; @@ -176,6 +176,7 @@ - (void)viewDidLoad { // Setup like label CGRect likesLabelRect = [self frameForLikesLabel]; _likesLabel = [[UILabel alloc] initWithFrame:likesLabelRect]; + [_likesLabel setFont:[UIFont systemFontOfSize:22]]; _likesLabel.textColor = [UIColor colorWithRed:172.0/255.0 green:172.0/255.0 blue:172.0/255.0 alpha:1]; _likesLabel.numberOfLines = 1; [_likesContainer addSubview:_likesLabel]; @@ -213,6 +214,8 @@ - (void)viewDidLoad { [self.view addGestureRecognizer:swipeGesture]; } + [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-60, -60) forBarMetrics:UIBarMetricsDefault]; + // Super [super viewDidLoad]; @@ -332,6 +335,7 @@ - (void)viewDidUnload { _previousButton = nil; _nextButton = nil; _progressHUD = nil; + [super viewDidUnload]; } @@ -469,16 +473,18 @@ - (void)didMoveToParentViewController:(UIViewController *)parent { - (void)setNavBarAppearance:(BOOL)animated { [self.navigationController setNavigationBarHidden:NO animated:animated]; UINavigationBar *navBar = self.navigationController.navigationBar; -// navBar.tintColor = [UIColor whiteColor]; -// navBar.barTintColor = nil; + navBar.tintColor = [UIColor whiteColor]; + navBar.barTintColor = nil; navBar.tintColor = [UIColor whiteColor]; navBar.barTintColor = [UIColor clearColor]; navBar.shadowImage = nil; navBar.translucent = YES; navBar.barStyle = UIBarStyleBlackTranslucent; - //UIImage *imageForButton = [UIImage imageForResourcePath:@"MWPhotoBrowser.bundle/back_arrow_white" ofType:@"png" inBundle:[NSBundle bundleForClass:[self class]]]; - UIImage *imageForButton = [UIImage imageNamed:@"back_arrow_white"]; - self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:imageForButton style:UIBarButtonItemStylePlain target:self action:@selector(backButtonPressed:)]; +// self.navigationItem.leftBarButtonItem.title = @""; +// self.navigationItem.backBarButtonItem.title = @""; +// self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:self.navigationItem.backBarButtonItem.style target:nil action:nil]; +// UIImage *imageForButton = [UIImage imageNamed:@"back_arrow"]; +// self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:imageForButton style:UIBarButtonItemStylePlain target:self action:@selector(backButtonPressed:)]; [navBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault]; [navBar setBackgroundImage:nil forBarMetrics:UIBarMetricsLandscapePhone]; } @@ -1036,7 +1042,7 @@ - (CGRect)frameForPagingScrollView { } - (CGRect)frameForLikesContainer { - CGFloat containerWidth = 100; + CGFloat containerWidth = 120; CGFloat containerHeight = 40; CGRect scrollViewFrame = [self frameForPagingScrollView]; CGFloat posX = scrollViewFrame.size.width / 2 - containerWidth / 2; From d61d48883a3711a7149218597e1b98629404d61d Mon Sep 17 00:00:00 2001 From: Sergey Demchenko Date: Wed, 24 Apr 2019 15:29:31 -0700 Subject: [PATCH 06/10] Update pod. --- Pod/Assets/.gitkeep | 0 Pod/Classes/.gitkeep | 0 Pod/Classes/MWPhotoBrowser.h | 14 ++- Pod/Classes/MWPhotoBrowser.m | 162 +++++++++++++++++++++----- Pod/Classes/MWPhotoBrowserPrivate.h | 1 - Pod/Classes/MWTapDetectingImageView.h | 2 +- Pod/Classes/MWZoomingScrollView.h | 1 + Pod/Classes/MWZoomingScrollView.m | 13 ++- 8 files changed, 157 insertions(+), 36 deletions(-) delete mode 100644 Pod/Assets/.gitkeep delete mode 100644 Pod/Classes/.gitkeep diff --git a/Pod/Assets/.gitkeep b/Pod/Assets/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/Pod/Classes/.gitkeep b/Pod/Classes/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/Pod/Classes/MWPhotoBrowser.h b/Pod/Classes/MWPhotoBrowser.h index 82a4a0722..a2920b37d 100644 --- a/Pod/Classes/MWPhotoBrowser.h +++ b/Pod/Classes/MWPhotoBrowser.h @@ -40,13 +40,16 @@ @protocol MWProfilePhotosLikeActions +- (BOOL)canShowLikeAnimation; - (NSUInteger)likesCount:(NSInteger)photoIndex; - (BOOL)isLiked:(NSInteger)photoIndex; - (void)likePhoto:(NSInteger)photoIndex like:(BOOL)like; +- (void)showLikes:(NSInteger)photoIndex; +- (void)removeLikesView; @end -@interface MWPhotoBrowser : UIViewController +@interface MWPhotoBrowser : UIViewController @property (nonatomic, weak) IBOutlet id delegate; @property (nonatomic, weak) id fullscreenPhotoDelegate; @@ -61,6 +64,13 @@ @property (nonatomic) BOOL autoPlayOnAppear; @property (nonatomic) NSUInteger delayToHideElements; @property (nonatomic, readonly) NSUInteger currentIndex; +@property (nonatomic) NSUInteger currentPageIndex; +@property (nonatomic) UIView *transparentView; +@property (nonatomic) UIView *likesView; +@property (nonatomic) BOOL isLikesViewOpened; +@property (nonatomic) BOOL showShareButton; +@property (nonatomic) BOOL showLikesContainer; +@property (nonatomic, copy) void(^onShareButtonTappedBlock)(UIButton *button); // Customise image selection icons as they are the only icons with a colour tint // Icon should be located in the app's main bundle @@ -81,6 +91,8 @@ - (void)showNextPhotoAnimated:(BOOL)animated; - (void)showPreviousPhotoAnimated:(BOOL)animated; +// Like button +- (void)likeButtonPressed; - (void)update; @end diff --git a/Pod/Classes/MWPhotoBrowser.m b/Pod/Classes/MWPhotoBrowser.m index 69d4d2705..05001846a 100644 --- a/Pod/Classes/MWPhotoBrowser.m +++ b/Pod/Classes/MWPhotoBrowser.m @@ -82,6 +82,7 @@ - (void)_initialisation { _currentGridContentOffset = CGPointMake(0, CGFLOAT_MAX); _didSavePreviousStateOfNavBar = NO; self.automaticallyAdjustsScrollViewInsets = NO; + _isLikesViewOpened = NO; // Listen for MWPhoto notifications [[NSNotificationCenter defaultCenter] addObserver:self @@ -99,6 +100,7 @@ - (void)dealloc { [[SDImageCache sharedImageCache] clearMemory]; // clear memory } + - (void)releaseAllUnderlyingPhotos:(BOOL)preserveCurrent { // Create a copy in case this array is modified while we are looping through // Release photos @@ -159,29 +161,45 @@ - (void)viewDidLoad { _pagingScrollView.contentSize = [self contentSizeForPagingScrollView]; [self.view addSubview:_pagingScrollView]; - // Setup likes container under scroll view - CGRect likesContainerRect = [self frameForLikesContainer]; - _likesContainer = [[UIView alloc] initWithFrame:likesContainerRect]; - _likesContainer.backgroundColor = [UIColor clearColor]; - [self.view addSubview:_likesContainer]; - - // Setup like button - CGRect likesButtonRect = [self frameForLikeButton]; - _likesButton = [[UIButton alloc] initWithFrame:likesButtonRect]; - [_likesButton setImage:[UIImage imageNamed:@"like_unselected"] forState:UIControlStateNormal]; - [_likesButton setImage:[UIImage imageNamed:@"like_selected"] forState:UIControlStateSelected]; - [_likesButton addTarget:self action:@selector(likeButtonPressed) forControlEvents:UIControlEventTouchUpInside]; - [_likesContainer addSubview:_likesButton]; - - // Setup like label - CGRect likesLabelRect = [self frameForLikesLabel]; - _likesLabel = [[UILabel alloc] initWithFrame:likesLabelRect]; - [_likesLabel setFont:[UIFont systemFontOfSize:22]]; - _likesLabel.textColor = [UIColor colorWithRed:172.0/255.0 green:172.0/255.0 blue:172.0/255.0 alpha:1]; - _likesLabel.numberOfLines = 1; - [_likesContainer addSubview:_likesLabel]; - - + if (self.showLikesContainer) { + // Setup likes container under scroll view + CGRect likesContainerRect = [self frameForLikesContainer]; + _likesContainer = [[UIView alloc] initWithFrame:likesContainerRect]; + _likesContainer.backgroundColor = [UIColor clearColor]; + [self.view addSubview:_likesContainer]; + + // Setup like button + CGRect likesButtonRect = [self frameForLikeButton]; + _likesButton = [[UIButton alloc] initWithFrame:likesButtonRect]; + [_likesButton setImage:[UIImage imageNamed:@"like_unselected"] forState:UIControlStateNormal]; + [_likesButton setImage:[UIImage imageNamed:@"like_selected"] forState:UIControlStateSelected]; + [_likesButton addTarget:self action:@selector(likeButtonPressed) forControlEvents:UIControlEventTouchUpInside]; + [_likesContainer addSubview:_likesButton]; + + // Setup like label + CGRect likesLabelRect = [self frameForLikesLabel]; + _likesLabel = [[UILabel alloc] initWithFrame:likesLabelRect]; + [_likesLabel setFont:[UIFont systemFontOfSize:20]]; + [_likesLabel setUserInteractionEnabled:YES]; + UITapGestureRecognizer *tapOnLikesLabel = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showLikesView)]; + tapOnLikesLabel.delegate = self; + [_likesLabel addGestureRecognizer:tapOnLikesLabel]; + _likesLabel.textColor = [UIColor colorWithRed:172.0/255.0 green:172.0/255.0 blue:172.0/255.0 alpha:1]; + _likesLabel.numberOfLines = 1; + [_likesContainer addSubview:_likesLabel]; + } + + /// + if (self.showShareButton) { + CGRect shareButtonFrame = [self frameForShareButton]; + UIButton *shareButton = [[UIButton alloc] initWithFrame:shareButtonFrame]; + [shareButton setImage:[UIImage imageNamed:@"share"] forState:UIControlStateNormal]; + [shareButton addTarget:self action:@selector(onShareButtonTapped:) forControlEvents:UIControlEventTouchUpInside]; + [self.view addSubview:shareButton]; + } + + /// + // Toolbar _toolbar = [[UIToolbar alloc] initWithFrame:[self frameForToolbarAtOrientation:self.interfaceOrientation]]; _toolbar.tintColor = [UIColor whiteColor]; @@ -214,7 +232,10 @@ - (void)viewDidLoad { [self.view addGestureRecognizer:swipeGesture]; } - [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-60, -60) forBarMetrics:UIBarMetricsDefault]; + float version = [[[UIDevice currentDevice] systemVersion] floatValue]; + if (version < 11.0) { + [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-60, -60) forBarMetrics:UIBarMetricsDefault]; + } // Super [super viewDidLoad]; @@ -329,6 +350,8 @@ - (void)viewDidUnload { _likesContainer = nil; _likesLabel = nil; _likesButton = nil; + _transparentView = nil; + _likesView = nil; _visiblePages = nil; _recycledPages = nil; _toolbar = nil; @@ -384,6 +407,8 @@ - (void)viewWillAppear:(BOOL)animated { [self storePreviousNavBarAppearance]; } [self setNavBarAppearance:animated]; + [self.navigationController setNavigationBarHidden:self.isLikesViewOpened]; + // Update UI [self hideControlsAfterDelay]; @@ -431,8 +456,8 @@ - (void)viewWillDisappear:(BOOL)animated { // Check that we're disappearing for good // self.isMovingFromParentViewController just doesn't work, ever. Or self.isBeingDismissed - if ((_doneButton && self.navigationController.isBeingDismissed) || - ([self.navigationController.viewControllers objectAtIndex:0] != self && ![self.navigationController.viewControllers containsObject:self])) { + //if ((_doneButton && self.navigationController.isBeingDismissed) || + // ([self.navigationController.viewControllers objectAtIndex:0] != self && ![self.navigationController.viewControllers containsObject:self])) { // State _viewIsActive = NO; @@ -441,7 +466,7 @@ - (void)viewWillDisappear:(BOOL)animated { // Bar state / appearance [self restorePreviousNavBarAppearance:animated]; - } + //} // Controls [self.navigationController.navigationBar.layer removeAllAnimations]; // Stop all animations on nav bar @@ -503,6 +528,7 @@ - (void)storePreviousNavBarAppearance { - (void)restorePreviousNavBarAppearance:(BOOL)animated { if (_didSavePreviousStateOfNavBar) { [self.navigationController setNavigationBarHidden:_previousNavBarHidden animated:animated]; + [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]}]; UINavigationBar *navBar = self.navigationController.navigationBar; navBar.tintColor = _previousNavBarTintColor; navBar.translucent = _previousNavBarTranslucent; @@ -1014,10 +1040,10 @@ - (void)update _likesButton.selected = likedByMe; //Update likes container - NSUInteger *likes = [_fullscreenPhotoDelegate likesCount:_currentPageIndex]; + NSUInteger likes = [_fullscreenPhotoDelegate likesCount:_currentPageIndex]; if (likes > 0) { NSString *likesWord = likes == 1 ? @"like" : @"likes"; - _likesLabel.text = [NSString stringWithFormat:@"%d %@", likes, likesWord]; + _likesLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)likes, likesWord]; } else { _likesLabel.text = @"0 likes"; } @@ -1041,6 +1067,17 @@ - (CGRect)frameForPagingScrollView { return CGRectIntegral(frame); } +- (CGRect)frameForShareButton +{ + CGFloat containerWidth = 40; + CGFloat containerHeight = 40; + CGRect scrollViewFrame = [self frameForPagingScrollView]; + CGFloat posX = 12; + CGFloat posY = scrollViewFrame.origin.y + scrollViewFrame.size.height; + CGRect frame = CGRectMake(posX, posY, containerWidth, containerHeight); + return CGRectIntegral(frame); +} + - (CGRect)frameForLikesContainer { CGFloat containerWidth = 120; CGFloat containerHeight = 40; @@ -1734,6 +1771,73 @@ - (void)likeButtonPressed { [_fullscreenPhotoDelegate isLiked:_currentPageIndex]; } +- (void)onShareButtonTapped:(UIButton *)button +{ + if (self.onShareButtonTappedBlock) { + self.onShareButtonTappedBlock(button); + } +} + +// MARK: - Show likes view + +- (void)showLikesView { + if (!_isLikesViewOpened && ![_likesLabel.text isEqualToString:@""]) { + self.transparentView = [[UIView alloc] initWithFrame:self.view.frame]; + UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeLikesView)]; + tapGesture.delegate = self; + [self.transparentView addGestureRecognizer:tapGesture]; + [self.view addSubview:self.transparentView]; + + CGRect transparentViewFrame = self.transparentView.frame; + CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height; + CGFloat likesContainerWidth = transparentViewFrame.size.width * 0.75; + CGFloat likesContainerHeight = transparentViewFrame.size.height - statusBarHeight; + CGRect likersViewFrame = CGRectMake(self.view.frame.size.width, statusBarHeight, likesContainerWidth, likesContainerHeight); + self.likesView = [[UIView alloc] initWithFrame:likersViewFrame]; + [_transparentView addSubview:_likesView]; + [self.fullscreenPhotoDelegate showLikes:_currentPageIndex]; + [self animateLikesView]; + } +} + +- (void)animateLikesView { + CGRect likesViewFrame = self.likesView.frame; + [UIView animateWithDuration:0.5 animations:^{ + [self.transparentView setBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.5]]; + self.likesView.frame = CGRectMake(self.view.frame.size.width - likesViewFrame.size.width, likesViewFrame.origin.y, likesViewFrame.size.width, likesViewFrame.size.height); + [self.navigationController setNavigationBarHidden:YES]; + } completion:^(BOOL finished) { + _isLikesViewOpened = YES; + }]; +} + +- (void)closeLikesView { + CGRect likesViewFrame = self.likesView.frame; + CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height; + [UIView animateWithDuration:0.5 animations:^{ + [self.transparentView setBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0]]; + self.likesView.frame = CGRectMake(self.view.frame.size.width, statusBarHeight, likesViewFrame.size.width, likesViewFrame.size.height); + } completion:^(BOOL finished) { + [self.navigationController setNavigationBarHidden:NO]; + [_fullscreenPhotoDelegate removeLikesView]; + [_likesView removeFromSuperview]; + [_transparentView removeFromSuperview]; + _likesView = nil; + _transparentView = nil; + _isLikesViewOpened = NO; + }]; +} + +// MARK: - UITapGestureRecognizer + +- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { + if (touch.view == _transparentView || touch.view == _likesLabel) { + return YES; + } else { + return NO; + } +} + #pragma mark - Action Progress - (MBProgressHUD *)progressHUD { diff --git a/Pod/Classes/MWPhotoBrowserPrivate.h b/Pod/Classes/MWPhotoBrowserPrivate.h index ff2ff6b9c..374d9023b 100644 --- a/Pod/Classes/MWPhotoBrowserPrivate.h +++ b/Pod/Classes/MWPhotoBrowserPrivate.h @@ -29,7 +29,6 @@ // Paging & layout NSMutableSet *_visiblePages, *_recycledPages; - NSUInteger _currentPageIndex; NSUInteger _previousPageIndex; CGRect _previousLayoutBounds; NSUInteger _pageIndexBeforeRotation; diff --git a/Pod/Classes/MWTapDetectingImageView.h b/Pod/Classes/MWTapDetectingImageView.h index 8445b6260..1393556c7 100644 --- a/Pod/Classes/MWTapDetectingImageView.h +++ b/Pod/Classes/MWTapDetectingImageView.h @@ -24,4 +24,4 @@ - (void)imageView:(UIImageView *)imageView doubleTapDetected:(UITouch *)touch; - (void)imageView:(UIImageView *)imageView tripleTapDetected:(UITouch *)touch; -@end \ No newline at end of file +@end diff --git a/Pod/Classes/MWZoomingScrollView.h b/Pod/Classes/MWZoomingScrollView.h index 4694ecffc..7ef5f886f 100644 --- a/Pod/Classes/MWZoomingScrollView.h +++ b/Pod/Classes/MWZoomingScrollView.h @@ -22,6 +22,7 @@ @property (nonatomic, weak) MWCaptionView *captionView; @property (nonatomic, weak) UIButton *selectedButton; @property (nonatomic, weak) UIButton *playButton; +@property (nonatomic, weak) MWPhotoBrowser *photoBrowser; - (id)initWithPhotoBrowser:(MWPhotoBrowser *)browser; - (void)displayImage; diff --git a/Pod/Classes/MWZoomingScrollView.m b/Pod/Classes/MWZoomingScrollView.m index 0f8c420be..df455492e 100644 --- a/Pod/Classes/MWZoomingScrollView.m +++ b/Pod/Classes/MWZoomingScrollView.m @@ -428,20 +428,25 @@ - (void)imageView:(UIImageView *)imageView singleTapDetected:(UITouch *)touch { [self handleSingleTap:[touch locationInView:imageView]]; } -- (void)imageView:(UIImageView *)imageView doubleTapDetected:(UITouch *)touch { +- (void)imageView:(UIImageView *)imageView doubleTapDetected:(UITouch *)touch +{ + if (!self.photoBrowser.showLikesContainer) { return; } + + if (![self.photoBrowser.fullscreenPhotoDelegate canShowLikeAnimation]) { return; } + UIImageView *likeAnimationView = [[UIImageView alloc] initWithFrame:[self frameForLikeAnimation:self.frame]]; likeAnimationView.image = [UIImage imageNamed:@"big_heart"]; likeAnimationView.contentMode = UIViewContentModeScaleAspectFit; [self addSubview:likeAnimationView]; - [UIView animateWithDuration:0.1f delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ + [UIView animateWithDuration:0.2f delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ likeAnimationView.transform = CGAffineTransformMakeScale(1.3, 1.3); likeAnimationView.alpha = 1.0; } completion:^(BOOL finished) { - [UIView animateWithDuration:0.1f delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ + [UIView animateWithDuration:0.2f delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ likeAnimationView.transform = CGAffineTransformMakeScale(1.0, 1.0); } completion:^(BOOL finished) { - [UIView animateWithDuration:0.1f delay:0.3 options:UIViewAnimationOptionAllowUserInteraction animations:^{ + [UIView animateWithDuration:0.2f delay:0.3 options:UIViewAnimationOptionAllowUserInteraction animations:^{ likeAnimationView.transform = CGAffineTransformMakeScale(0.3, 0.3); likeAnimationView.alpha = 0.0; } completion:^(BOOL finished) { From 89cde2226ff06771c1302f5d965adc220064222e Mon Sep 17 00:00:00 2001 From: Sergey Demchenko Date: Tue, 27 Aug 2019 22:56:30 +0300 Subject: [PATCH 07/10] Fix title appearing WIP --- Pod/Classes/MWPhotoBrowser.m | 31 +++++++++-------------------- Pod/Classes/MWPhotoBrowserPrivate.h | 1 + 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/Pod/Classes/MWPhotoBrowser.m b/Pod/Classes/MWPhotoBrowser.m index 05001846a..3b0d3c86d 100644 --- a/Pod/Classes/MWPhotoBrowser.m +++ b/Pod/Classes/MWPhotoBrowser.m @@ -454,19 +454,12 @@ - (void)viewWillDisappear:(BOOL)animated { // Detect if rotation occurs while we're presenting a modal _pageIndexBeforeRotation = _currentPageIndex; - // Check that we're disappearing for good - // self.isMovingFromParentViewController just doesn't work, ever. Or self.isBeingDismissed - //if ((_doneButton && self.navigationController.isBeingDismissed) || - // ([self.navigationController.viewControllers objectAtIndex:0] != self && ![self.navigationController.viewControllers containsObject:self])) { - - // State - _viewIsActive = NO; - [self clearCurrentVideo]; // Clear current playing video - - // Bar state / appearance - [self restorePreviousNavBarAppearance:animated]; - - //} + // State + _viewIsActive = NO; + [self clearCurrentVideo]; // Clear current playing video + + // Bar state / appearance + [self restorePreviousNavBarAppearance:YES]; // Controls [self.navigationController.navigationBar.layer removeAllAnimations]; // Stop all animations on nav bar @@ -498,24 +491,17 @@ - (void)didMoveToParentViewController:(UIViewController *)parent { - (void)setNavBarAppearance:(BOOL)animated { [self.navigationController setNavigationBarHidden:NO animated:animated]; UINavigationBar *navBar = self.navigationController.navigationBar; - navBar.tintColor = [UIColor whiteColor]; - navBar.barTintColor = nil; - navBar.tintColor = [UIColor whiteColor]; - navBar.barTintColor = [UIColor clearColor]; navBar.shadowImage = nil; navBar.translucent = YES; navBar.barStyle = UIBarStyleBlackTranslucent; -// self.navigationItem.leftBarButtonItem.title = @""; -// self.navigationItem.backBarButtonItem.title = @""; -// self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:self.navigationItem.backBarButtonItem.style target:nil action:nil]; -// UIImage *imageForButton = [UIImage imageNamed:@"back_arrow"]; -// self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:imageForButton style:UIBarButtonItemStylePlain target:self action:@selector(backButtonPressed:)]; + navBar.titleTextAttributes = nil; [navBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault]; [navBar setBackgroundImage:nil forBarMetrics:UIBarMetricsLandscapePhone]; } - (void)storePreviousNavBarAppearance { _didSavePreviousStateOfNavBar = YES; + _previousNavBarTitleAttributes = self.navigationController.navigationBar.titleTextAttributes; _previousNavBarBarTintColor = self.navigationController.navigationBar.barTintColor; _previousNavBarTranslucent = self.navigationController.navigationBar.translucent; _previousNavBarTintColor = self.navigationController.navigationBar.tintColor; @@ -534,6 +520,7 @@ - (void)restorePreviousNavBarAppearance:(BOOL)animated { navBar.translucent = _previousNavBarTranslucent; navBar.barTintColor = _previousNavBarBarTintColor; navBar.barStyle = _previousNavBarStyle; + navBar.titleTextAttributes = _previousNavBarTitleAttributes; [navBar setBackgroundImage:_previousNavigationBarBackgroundImageDefault forBarMetrics:UIBarMetricsDefault]; [navBar setBackgroundImage:_previousNavigationBarBackgroundImageLandscapePhone forBarMetrics:UIBarMetricsLandscapePhone]; // Restore back button if we need to diff --git a/Pod/Classes/MWPhotoBrowserPrivate.h b/Pod/Classes/MWPhotoBrowserPrivate.h index 374d9023b..777be9167 100644 --- a/Pod/Classes/MWPhotoBrowserPrivate.h +++ b/Pod/Classes/MWPhotoBrowserPrivate.h @@ -54,6 +54,7 @@ UIBarButtonItem *_previousViewControllerBackButton; UIImage *_previousNavigationBarBackgroundImageDefault; UIImage *_previousNavigationBarBackgroundImageLandscapePhone; + NSDictionary *_previousNavBarTitleAttributes; // Video MPMoviePlayerViewController *_currentVideoPlayerViewController; From 20f992af843e26eb7e86b35e148b19c392d4a95f Mon Sep 17 00:00:00 2001 From: Sergey Demchenko Date: Tue, 27 Aug 2019 23:10:10 +0300 Subject: [PATCH 08/10] Fix title appearing WIP --- Pod/Classes/MWPhotoBrowser.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Pod/Classes/MWPhotoBrowser.m b/Pod/Classes/MWPhotoBrowser.m index 3b0d3c86d..2d2e0861a 100644 --- a/Pod/Classes/MWPhotoBrowser.m +++ b/Pod/Classes/MWPhotoBrowser.m @@ -458,9 +458,6 @@ - (void)viewWillDisappear:(BOOL)animated { _viewIsActive = NO; [self clearCurrentVideo]; // Clear current playing video - // Bar state / appearance - [self restorePreviousNavBarAppearance:YES]; - // Controls [self.navigationController.navigationBar.layer removeAllAnimations]; // Stop all animations on nav bar [NSObject cancelPreviousPerformRequestsWithTarget:self]; // Cancel any pending toggles from taps @@ -480,6 +477,9 @@ - (void)willMoveToParentViewController:(UIViewController *)parent { if (parent && _hasBelongedToViewController) { [NSException raise:@"MWPhotoBrowser Instance Reuse" format:@"MWPhotoBrowser instances cannot be reused."]; } + + // Bar state / appearance + [self restorePreviousNavBarAppearance:YES]; } - (void)didMoveToParentViewController:(UIViewController *)parent { From 32535833e13076c71ac2efb47812be23e1b401ec Mon Sep 17 00:00:00 2001 From: Sergey Demchenko Date: Tue, 27 Aug 2019 23:25:43 +0300 Subject: [PATCH 09/10] Fix navbar appearing --- Pod/Classes/MWPhotoBrowser.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Pod/Classes/MWPhotoBrowser.m b/Pod/Classes/MWPhotoBrowser.m index 2d2e0861a..2492b1f58 100644 --- a/Pod/Classes/MWPhotoBrowser.m +++ b/Pod/Classes/MWPhotoBrowser.m @@ -458,6 +458,9 @@ - (void)viewWillDisappear:(BOOL)animated { _viewIsActive = NO; [self clearCurrentVideo]; // Clear current playing video + // Bar state / appearance + [self restorePreviousNavBarAppearance:animated]; + // Controls [self.navigationController.navigationBar.layer removeAllAnimations]; // Stop all animations on nav bar [NSObject cancelPreviousPerformRequestsWithTarget:self]; // Cancel any pending toggles from taps From 81f87664d0bab8771da79bf7d95eb775744ed5ef Mon Sep 17 00:00:00 2001 From: Timur Piriev Date: Thu, 14 Nov 2019 23:20:31 +0200 Subject: [PATCH 10/10] Remove likes container --- Pod/Classes/MWPhotoBrowser.h | 3 -- Pod/Classes/MWPhotoBrowser.m | 55 ++---------------------------------- 2 files changed, 2 insertions(+), 56 deletions(-) diff --git a/Pod/Classes/MWPhotoBrowser.h b/Pod/Classes/MWPhotoBrowser.h index a2920b37d..91c12eef6 100644 --- a/Pod/Classes/MWPhotoBrowser.h +++ b/Pod/Classes/MWPhotoBrowser.h @@ -65,9 +65,6 @@ @property (nonatomic) NSUInteger delayToHideElements; @property (nonatomic, readonly) NSUInteger currentIndex; @property (nonatomic) NSUInteger currentPageIndex; -@property (nonatomic) UIView *transparentView; -@property (nonatomic) UIView *likesView; -@property (nonatomic) BOOL isLikesViewOpened; @property (nonatomic) BOOL showShareButton; @property (nonatomic) BOOL showLikesContainer; @property (nonatomic, copy) void(^onShareButtonTappedBlock)(UIButton *button); diff --git a/Pod/Classes/MWPhotoBrowser.m b/Pod/Classes/MWPhotoBrowser.m index 2492b1f58..ca6198dd1 100644 --- a/Pod/Classes/MWPhotoBrowser.m +++ b/Pod/Classes/MWPhotoBrowser.m @@ -82,7 +82,6 @@ - (void)_initialisation { _currentGridContentOffset = CGPointMake(0, CGFLOAT_MAX); _didSavePreviousStateOfNavBar = NO; self.automaticallyAdjustsScrollViewInsets = NO; - _isLikesViewOpened = NO; // Listen for MWPhoto notifications [[NSNotificationCenter defaultCenter] addObserver:self @@ -350,8 +349,6 @@ - (void)viewDidUnload { _likesContainer = nil; _likesLabel = nil; _likesButton = nil; - _transparentView = nil; - _likesView = nil; _visiblePages = nil; _recycledPages = nil; _toolbar = nil; @@ -407,8 +404,6 @@ - (void)viewWillAppear:(BOOL)animated { [self storePreviousNavBarAppearance]; } [self setNavBarAppearance:animated]; - [self.navigationController setNavigationBarHidden:self.isLikesViewOpened]; - // Update UI [self hideControlsAfterDelay]; @@ -1771,61 +1766,15 @@ - (void)onShareButtonTapped:(UIButton *)button // MARK: - Show likes view - (void)showLikesView { - if (!_isLikesViewOpened && ![_likesLabel.text isEqualToString:@""]) { - self.transparentView = [[UIView alloc] initWithFrame:self.view.frame]; - UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeLikesView)]; - tapGesture.delegate = self; - [self.transparentView addGestureRecognizer:tapGesture]; - [self.view addSubview:self.transparentView]; - - CGRect transparentViewFrame = self.transparentView.frame; - CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height; - CGFloat likesContainerWidth = transparentViewFrame.size.width * 0.75; - CGFloat likesContainerHeight = transparentViewFrame.size.height - statusBarHeight; - CGRect likersViewFrame = CGRectMake(self.view.frame.size.width, statusBarHeight, likesContainerWidth, likesContainerHeight); - self.likesView = [[UIView alloc] initWithFrame:likersViewFrame]; - [_transparentView addSubview:_likesView]; + if (self.fullscreenPhotoDelegate && ![_likesLabel.text isEqualToString:@""]) { [self.fullscreenPhotoDelegate showLikes:_currentPageIndex]; - [self animateLikesView]; } } -- (void)animateLikesView { - CGRect likesViewFrame = self.likesView.frame; - [UIView animateWithDuration:0.5 animations:^{ - [self.transparentView setBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.5]]; - self.likesView.frame = CGRectMake(self.view.frame.size.width - likesViewFrame.size.width, likesViewFrame.origin.y, likesViewFrame.size.width, likesViewFrame.size.height); - [self.navigationController setNavigationBarHidden:YES]; - } completion:^(BOOL finished) { - _isLikesViewOpened = YES; - }]; -} - -- (void)closeLikesView { - CGRect likesViewFrame = self.likesView.frame; - CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height; - [UIView animateWithDuration:0.5 animations:^{ - [self.transparentView setBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0]]; - self.likesView.frame = CGRectMake(self.view.frame.size.width, statusBarHeight, likesViewFrame.size.width, likesViewFrame.size.height); - } completion:^(BOOL finished) { - [self.navigationController setNavigationBarHidden:NO]; - [_fullscreenPhotoDelegate removeLikesView]; - [_likesView removeFromSuperview]; - [_transparentView removeFromSuperview]; - _likesView = nil; - _transparentView = nil; - _isLikesViewOpened = NO; - }]; -} - // MARK: - UITapGestureRecognizer - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { - if (touch.view == _transparentView || touch.view == _likesLabel) { - return YES; - } else { - return NO; - } + return touch.view == _likesLabel; } #pragma mark - Action Progress