Skip to content

Commit d61d488

Browse files
committed
Update pod.
1 parent f7ea3e3 commit d61d488

File tree

8 files changed

+157
-36
lines changed

8 files changed

+157
-36
lines changed

Pod/Assets/.gitkeep

Whitespace-only changes.

Pod/Classes/.gitkeep

Whitespace-only changes.

Pod/Classes/MWPhotoBrowser.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,16 @@
4040

4141
@protocol MWProfilePhotosLikeActions <NSObject>
4242

43+
- (BOOL)canShowLikeAnimation;
4344
- (NSUInteger)likesCount:(NSInteger)photoIndex;
4445
- (BOOL)isLiked:(NSInteger)photoIndex;
4546
- (void)likePhoto:(NSInteger)photoIndex like:(BOOL)like;
47+
- (void)showLikes:(NSInteger)photoIndex;
48+
- (void)removeLikesView;
4649

4750
@end
4851

49-
@interface MWPhotoBrowser : UIViewController <UIScrollViewDelegate, UIActionSheetDelegate>
52+
@interface MWPhotoBrowser : UIViewController <UIScrollViewDelegate, UIActionSheetDelegate, UIGestureRecognizerDelegate>
5053

5154
@property (nonatomic, weak) IBOutlet id<MWPhotoBrowserDelegate> delegate;
5255
@property (nonatomic, weak) id<MWProfilePhotosLikeActions> fullscreenPhotoDelegate;
@@ -61,6 +64,13 @@
6164
@property (nonatomic) BOOL autoPlayOnAppear;
6265
@property (nonatomic) NSUInteger delayToHideElements;
6366
@property (nonatomic, readonly) NSUInteger currentIndex;
67+
@property (nonatomic) NSUInteger currentPageIndex;
68+
@property (nonatomic) UIView *transparentView;
69+
@property (nonatomic) UIView *likesView;
70+
@property (nonatomic) BOOL isLikesViewOpened;
71+
@property (nonatomic) BOOL showShareButton;
72+
@property (nonatomic) BOOL showLikesContainer;
73+
@property (nonatomic, copy) void(^onShareButtonTappedBlock)(UIButton *button);
6474

6575
// Customise image selection icons as they are the only icons with a colour tint
6676
// Icon should be located in the app's main bundle
@@ -81,6 +91,8 @@
8191
- (void)showNextPhotoAnimated:(BOOL)animated;
8292
- (void)showPreviousPhotoAnimated:(BOOL)animated;
8393

94+
// Like button
95+
- (void)likeButtonPressed;
8496
- (void)update;
8597

8698
@end

Pod/Classes/MWPhotoBrowser.m

Lines changed: 133 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ - (void)_initialisation {
8282
_currentGridContentOffset = CGPointMake(0, CGFLOAT_MAX);
8383
_didSavePreviousStateOfNavBar = NO;
8484
self.automaticallyAdjustsScrollViewInsets = NO;
85+
_isLikesViewOpened = NO;
8586

8687
// Listen for MWPhoto notifications
8788
[[NSNotificationCenter defaultCenter] addObserver:self
@@ -99,6 +100,7 @@ - (void)dealloc {
99100
[[SDImageCache sharedImageCache] clearMemory]; // clear memory
100101
}
101102

103+
102104
- (void)releaseAllUnderlyingPhotos:(BOOL)preserveCurrent {
103105
// Create a copy in case this array is modified while we are looping through
104106
// Release photos
@@ -159,29 +161,45 @@ - (void)viewDidLoad {
159161
_pagingScrollView.contentSize = [self contentSizeForPagingScrollView];
160162
[self.view addSubview:_pagingScrollView];
161163

162-
// Setup likes container under scroll view
163-
CGRect likesContainerRect = [self frameForLikesContainer];
164-
_likesContainer = [[UIView alloc] initWithFrame:likesContainerRect];
165-
_likesContainer.backgroundColor = [UIColor clearColor];
166-
[self.view addSubview:_likesContainer];
167-
168-
// Setup like button
169-
CGRect likesButtonRect = [self frameForLikeButton];
170-
_likesButton = [[UIButton alloc] initWithFrame:likesButtonRect];
171-
[_likesButton setImage:[UIImage imageNamed:@"like_unselected"] forState:UIControlStateNormal];
172-
[_likesButton setImage:[UIImage imageNamed:@"like_selected"] forState:UIControlStateSelected];
173-
[_likesButton addTarget:self action:@selector(likeButtonPressed) forControlEvents:UIControlEventTouchUpInside];
174-
[_likesContainer addSubview:_likesButton];
175-
176-
// Setup like label
177-
CGRect likesLabelRect = [self frameForLikesLabel];
178-
_likesLabel = [[UILabel alloc] initWithFrame:likesLabelRect];
179-
[_likesLabel setFont:[UIFont systemFontOfSize:22]];
180-
_likesLabel.textColor = [UIColor colorWithRed:172.0/255.0 green:172.0/255.0 blue:172.0/255.0 alpha:1];
181-
_likesLabel.numberOfLines = 1;
182-
[_likesContainer addSubview:_likesLabel];
183-
184-
164+
if (self.showLikesContainer) {
165+
// Setup likes container under scroll view
166+
CGRect likesContainerRect = [self frameForLikesContainer];
167+
_likesContainer = [[UIView alloc] initWithFrame:likesContainerRect];
168+
_likesContainer.backgroundColor = [UIColor clearColor];
169+
[self.view addSubview:_likesContainer];
170+
171+
// Setup like button
172+
CGRect likesButtonRect = [self frameForLikeButton];
173+
_likesButton = [[UIButton alloc] initWithFrame:likesButtonRect];
174+
[_likesButton setImage:[UIImage imageNamed:@"like_unselected"] forState:UIControlStateNormal];
175+
[_likesButton setImage:[UIImage imageNamed:@"like_selected"] forState:UIControlStateSelected];
176+
[_likesButton addTarget:self action:@selector(likeButtonPressed) forControlEvents:UIControlEventTouchUpInside];
177+
[_likesContainer addSubview:_likesButton];
178+
179+
// Setup like label
180+
CGRect likesLabelRect = [self frameForLikesLabel];
181+
_likesLabel = [[UILabel alloc] initWithFrame:likesLabelRect];
182+
[_likesLabel setFont:[UIFont systemFontOfSize:20]];
183+
[_likesLabel setUserInteractionEnabled:YES];
184+
UITapGestureRecognizer *tapOnLikesLabel = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showLikesView)];
185+
tapOnLikesLabel.delegate = self;
186+
[_likesLabel addGestureRecognizer:tapOnLikesLabel];
187+
_likesLabel.textColor = [UIColor colorWithRed:172.0/255.0 green:172.0/255.0 blue:172.0/255.0 alpha:1];
188+
_likesLabel.numberOfLines = 1;
189+
[_likesContainer addSubview:_likesLabel];
190+
}
191+
192+
///
193+
if (self.showShareButton) {
194+
CGRect shareButtonFrame = [self frameForShareButton];
195+
UIButton *shareButton = [[UIButton alloc] initWithFrame:shareButtonFrame];
196+
[shareButton setImage:[UIImage imageNamed:@"share"] forState:UIControlStateNormal];
197+
[shareButton addTarget:self action:@selector(onShareButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
198+
[self.view addSubview:shareButton];
199+
}
200+
201+
///
202+
185203
// Toolbar
186204
_toolbar = [[UIToolbar alloc] initWithFrame:[self frameForToolbarAtOrientation:self.interfaceOrientation]];
187205
_toolbar.tintColor = [UIColor whiteColor];
@@ -214,7 +232,10 @@ - (void)viewDidLoad {
214232
[self.view addGestureRecognizer:swipeGesture];
215233
}
216234

217-
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-60, -60) forBarMetrics:UIBarMetricsDefault];
235+
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
236+
if (version < 11.0) {
237+
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-60, -60) forBarMetrics:UIBarMetricsDefault];
238+
}
218239

219240
// Super
220241
[super viewDidLoad];
@@ -329,6 +350,8 @@ - (void)viewDidUnload {
329350
_likesContainer = nil;
330351
_likesLabel = nil;
331352
_likesButton = nil;
353+
_transparentView = nil;
354+
_likesView = nil;
332355
_visiblePages = nil;
333356
_recycledPages = nil;
334357
_toolbar = nil;
@@ -384,6 +407,8 @@ - (void)viewWillAppear:(BOOL)animated {
384407
[self storePreviousNavBarAppearance];
385408
}
386409
[self setNavBarAppearance:animated];
410+
[self.navigationController setNavigationBarHidden:self.isLikesViewOpened];
411+
387412

388413
// Update UI
389414
[self hideControlsAfterDelay];
@@ -431,8 +456,8 @@ - (void)viewWillDisappear:(BOOL)animated {
431456

432457
// Check that we're disappearing for good
433458
// self.isMovingFromParentViewController just doesn't work, ever. Or self.isBeingDismissed
434-
if ((_doneButton && self.navigationController.isBeingDismissed) ||
435-
([self.navigationController.viewControllers objectAtIndex:0] != self && ![self.navigationController.viewControllers containsObject:self])) {
459+
//if ((_doneButton && self.navigationController.isBeingDismissed) ||
460+
// ([self.navigationController.viewControllers objectAtIndex:0] != self && ![self.navigationController.viewControllers containsObject:self])) {
436461

437462
// State
438463
_viewIsActive = NO;
@@ -441,7 +466,7 @@ - (void)viewWillDisappear:(BOOL)animated {
441466
// Bar state / appearance
442467
[self restorePreviousNavBarAppearance:animated];
443468

444-
}
469+
//}
445470

446471
// Controls
447472
[self.navigationController.navigationBar.layer removeAllAnimations]; // Stop all animations on nav bar
@@ -503,6 +528,7 @@ - (void)storePreviousNavBarAppearance {
503528
- (void)restorePreviousNavBarAppearance:(BOOL)animated {
504529
if (_didSavePreviousStateOfNavBar) {
505530
[self.navigationController setNavigationBarHidden:_previousNavBarHidden animated:animated];
531+
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]}];
506532
UINavigationBar *navBar = self.navigationController.navigationBar;
507533
navBar.tintColor = _previousNavBarTintColor;
508534
navBar.translucent = _previousNavBarTranslucent;
@@ -1014,10 +1040,10 @@ - (void)update
10141040
_likesButton.selected = likedByMe;
10151041

10161042
//Update likes container
1017-
NSUInteger *likes = [_fullscreenPhotoDelegate likesCount:_currentPageIndex];
1043+
NSUInteger likes = [_fullscreenPhotoDelegate likesCount:_currentPageIndex];
10181044
if (likes > 0) {
10191045
NSString *likesWord = likes == 1 ? @"like" : @"likes";
1020-
_likesLabel.text = [NSString stringWithFormat:@"%d %@", likes, likesWord];
1046+
_likesLabel.text = [NSString stringWithFormat:@"%lu %@", (unsigned long)likes, likesWord];
10211047
} else {
10221048
_likesLabel.text = @"0 likes";
10231049
}
@@ -1041,6 +1067,17 @@ - (CGRect)frameForPagingScrollView {
10411067
return CGRectIntegral(frame);
10421068
}
10431069

1070+
- (CGRect)frameForShareButton
1071+
{
1072+
CGFloat containerWidth = 40;
1073+
CGFloat containerHeight = 40;
1074+
CGRect scrollViewFrame = [self frameForPagingScrollView];
1075+
CGFloat posX = 12;
1076+
CGFloat posY = scrollViewFrame.origin.y + scrollViewFrame.size.height;
1077+
CGRect frame = CGRectMake(posX, posY, containerWidth, containerHeight);
1078+
return CGRectIntegral(frame);
1079+
}
1080+
10441081
- (CGRect)frameForLikesContainer {
10451082
CGFloat containerWidth = 120;
10461083
CGFloat containerHeight = 40;
@@ -1734,6 +1771,73 @@ - (void)likeButtonPressed {
17341771
[_fullscreenPhotoDelegate isLiked:_currentPageIndex];
17351772
}
17361773

1774+
- (void)onShareButtonTapped:(UIButton *)button
1775+
{
1776+
if (self.onShareButtonTappedBlock) {
1777+
self.onShareButtonTappedBlock(button);
1778+
}
1779+
}
1780+
1781+
// MARK: - Show likes view
1782+
1783+
- (void)showLikesView {
1784+
if (!_isLikesViewOpened && ![_likesLabel.text isEqualToString:@""]) {
1785+
self.transparentView = [[UIView alloc] initWithFrame:self.view.frame];
1786+
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeLikesView)];
1787+
tapGesture.delegate = self;
1788+
[self.transparentView addGestureRecognizer:tapGesture];
1789+
[self.view addSubview:self.transparentView];
1790+
1791+
CGRect transparentViewFrame = self.transparentView.frame;
1792+
CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
1793+
CGFloat likesContainerWidth = transparentViewFrame.size.width * 0.75;
1794+
CGFloat likesContainerHeight = transparentViewFrame.size.height - statusBarHeight;
1795+
CGRect likersViewFrame = CGRectMake(self.view.frame.size.width, statusBarHeight, likesContainerWidth, likesContainerHeight);
1796+
self.likesView = [[UIView alloc] initWithFrame:likersViewFrame];
1797+
[_transparentView addSubview:_likesView];
1798+
[self.fullscreenPhotoDelegate showLikes:_currentPageIndex];
1799+
[self animateLikesView];
1800+
}
1801+
}
1802+
1803+
- (void)animateLikesView {
1804+
CGRect likesViewFrame = self.likesView.frame;
1805+
[UIView animateWithDuration:0.5 animations:^{
1806+
[self.transparentView setBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0.5]];
1807+
self.likesView.frame = CGRectMake(self.view.frame.size.width - likesViewFrame.size.width, likesViewFrame.origin.y, likesViewFrame.size.width, likesViewFrame.size.height);
1808+
[self.navigationController setNavigationBarHidden:YES];
1809+
} completion:^(BOOL finished) {
1810+
_isLikesViewOpened = YES;
1811+
}];
1812+
}
1813+
1814+
- (void)closeLikesView {
1815+
CGRect likesViewFrame = self.likesView.frame;
1816+
CGFloat statusBarHeight = [UIApplication sharedApplication].statusBarFrame.size.height;
1817+
[UIView animateWithDuration:0.5 animations:^{
1818+
[self.transparentView setBackgroundColor:[[UIColor blackColor] colorWithAlphaComponent:0]];
1819+
self.likesView.frame = CGRectMake(self.view.frame.size.width, statusBarHeight, likesViewFrame.size.width, likesViewFrame.size.height);
1820+
} completion:^(BOOL finished) {
1821+
[self.navigationController setNavigationBarHidden:NO];
1822+
[_fullscreenPhotoDelegate removeLikesView];
1823+
[_likesView removeFromSuperview];
1824+
[_transparentView removeFromSuperview];
1825+
_likesView = nil;
1826+
_transparentView = nil;
1827+
_isLikesViewOpened = NO;
1828+
}];
1829+
}
1830+
1831+
// MARK: - UITapGestureRecognizer
1832+
1833+
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
1834+
if (touch.view == _transparentView || touch.view == _likesLabel) {
1835+
return YES;
1836+
} else {
1837+
return NO;
1838+
}
1839+
}
1840+
17371841
#pragma mark - Action Progress
17381842

17391843
- (MBProgressHUD *)progressHUD {

Pod/Classes/MWPhotoBrowserPrivate.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
// Paging & layout
3131
NSMutableSet *_visiblePages, *_recycledPages;
32-
NSUInteger _currentPageIndex;
3332
NSUInteger _previousPageIndex;
3433
CGRect _previousLayoutBounds;
3534
NSUInteger _pageIndexBeforeRotation;

Pod/Classes/MWTapDetectingImageView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@
2424
- (void)imageView:(UIImageView *)imageView doubleTapDetected:(UITouch *)touch;
2525
- (void)imageView:(UIImageView *)imageView tripleTapDetected:(UITouch *)touch;
2626

27-
@end
27+
@end

Pod/Classes/MWZoomingScrollView.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
@property (nonatomic, weak) MWCaptionView *captionView;
2323
@property (nonatomic, weak) UIButton *selectedButton;
2424
@property (nonatomic, weak) UIButton *playButton;
25+
@property (nonatomic, weak) MWPhotoBrowser *photoBrowser;
2526

2627
- (id)initWithPhotoBrowser:(MWPhotoBrowser *)browser;
2728
- (void)displayImage;

Pod/Classes/MWZoomingScrollView.m

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,20 +428,25 @@ - (void)imageView:(UIImageView *)imageView singleTapDetected:(UITouch *)touch {
428428
[self handleSingleTap:[touch locationInView:imageView]];
429429
}
430430

431-
- (void)imageView:(UIImageView *)imageView doubleTapDetected:(UITouch *)touch {
431+
- (void)imageView:(UIImageView *)imageView doubleTapDetected:(UITouch *)touch
432+
{
433+
if (!self.photoBrowser.showLikesContainer) { return; }
434+
435+
if (![self.photoBrowser.fullscreenPhotoDelegate canShowLikeAnimation]) { return; }
436+
432437
UIImageView *likeAnimationView = [[UIImageView alloc] initWithFrame:[self frameForLikeAnimation:self.frame]];
433438
likeAnimationView.image = [UIImage imageNamed:@"big_heart"];
434439
likeAnimationView.contentMode = UIViewContentModeScaleAspectFit;
435440
[self addSubview:likeAnimationView];
436441

437-
[UIView animateWithDuration:0.1f delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
442+
[UIView animateWithDuration:0.2f delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
438443
likeAnimationView.transform = CGAffineTransformMakeScale(1.3, 1.3);
439444
likeAnimationView.alpha = 1.0;
440445
} completion:^(BOOL finished) {
441-
[UIView animateWithDuration:0.1f delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
446+
[UIView animateWithDuration:0.2f delay:0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
442447
likeAnimationView.transform = CGAffineTransformMakeScale(1.0, 1.0);
443448
} completion:^(BOOL finished) {
444-
[UIView animateWithDuration:0.1f delay:0.3 options:UIViewAnimationOptionAllowUserInteraction animations:^{
449+
[UIView animateWithDuration:0.2f delay:0.3 options:UIViewAnimationOptionAllowUserInteraction animations:^{
445450
likeAnimationView.transform = CGAffineTransformMakeScale(0.3, 0.3);
446451
likeAnimationView.alpha = 0.0;
447452
} completion:^(BOOL finished) {

0 commit comments

Comments
 (0)