@@ -82,6 +82,7 @@ - (void)_initialisation {
82
82
_currentGridContentOffset = CGPointMake (0 , CGFLOAT_MAX);
83
83
_didSavePreviousStateOfNavBar = NO ;
84
84
self.automaticallyAdjustsScrollViewInsets = NO ;
85
+ _isLikesViewOpened = NO ;
85
86
86
87
// Listen for MWPhoto notifications
87
88
[[NSNotificationCenter defaultCenter ] addObserver: self
@@ -99,6 +100,7 @@ - (void)dealloc {
99
100
[[SDImageCache sharedImageCache ] clearMemory ]; // clear memory
100
101
}
101
102
103
+
102
104
- (void )releaseAllUnderlyingPhotos : (BOOL )preserveCurrent {
103
105
// Create a copy in case this array is modified while we are looping through
104
106
// Release photos
@@ -159,29 +161,45 @@ - (void)viewDidLoad {
159
161
_pagingScrollView.contentSize = [self contentSizeForPagingScrollView ];
160
162
[self .view addSubview: _pagingScrollView];
161
163
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
+
185
203
// Toolbar
186
204
_toolbar = [[UIToolbar alloc ] initWithFrame: [self frameForToolbarAtOrientation: self .interfaceOrientation]];
187
205
_toolbar.tintColor = [UIColor whiteColor ];
@@ -214,7 +232,10 @@ - (void)viewDidLoad {
214
232
[self .view addGestureRecognizer: swipeGesture];
215
233
}
216
234
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
+ }
218
239
219
240
// Super
220
241
[super viewDidLoad ];
@@ -329,6 +350,8 @@ - (void)viewDidUnload {
329
350
_likesContainer = nil ;
330
351
_likesLabel = nil ;
331
352
_likesButton = nil ;
353
+ _transparentView = nil ;
354
+ _likesView = nil ;
332
355
_visiblePages = nil ;
333
356
_recycledPages = nil ;
334
357
_toolbar = nil ;
@@ -384,6 +407,8 @@ - (void)viewWillAppear:(BOOL)animated {
384
407
[self storePreviousNavBarAppearance ];
385
408
}
386
409
[self setNavBarAppearance: animated];
410
+ [self .navigationController setNavigationBarHidden: self .isLikesViewOpened];
411
+
387
412
388
413
// Update UI
389
414
[self hideControlsAfterDelay ];
@@ -431,8 +456,8 @@ - (void)viewWillDisappear:(BOOL)animated {
431
456
432
457
// Check that we're disappearing for good
433
458
// 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])) {
436
461
437
462
// State
438
463
_viewIsActive = NO ;
@@ -441,7 +466,7 @@ - (void)viewWillDisappear:(BOOL)animated {
441
466
// Bar state / appearance
442
467
[self restorePreviousNavBarAppearance: animated];
443
468
444
- }
469
+ // }
445
470
446
471
// Controls
447
472
[self .navigationController.navigationBar.layer removeAllAnimations ]; // Stop all animations on nav bar
@@ -503,6 +528,7 @@ - (void)storePreviousNavBarAppearance {
503
528
- (void )restorePreviousNavBarAppearance : (BOOL )animated {
504
529
if (_didSavePreviousStateOfNavBar) {
505
530
[self .navigationController setNavigationBarHidden: _previousNavBarHidden animated: animated];
531
+ [self .navigationController.navigationBar setTitleTextAttributes: @{NSForegroundColorAttributeName :[UIColor blackColor ]}];
506
532
UINavigationBar *navBar = self.navigationController .navigationBar ;
507
533
navBar.tintColor = _previousNavBarTintColor;
508
534
navBar.translucent = _previousNavBarTranslucent;
@@ -1014,10 +1040,10 @@ - (void)update
1014
1040
_likesButton.selected = likedByMe;
1015
1041
1016
1042
// Update likes container
1017
- NSUInteger * likes = [_fullscreenPhotoDelegate likesCount: _currentPageIndex];
1043
+ NSUInteger likes = [_fullscreenPhotoDelegate likesCount: _currentPageIndex];
1018
1044
if (likes > 0 ) {
1019
1045
NSString *likesWord = likes == 1 ? @" like" : @" likes" ;
1020
- _likesLabel.text = [NSString stringWithFormat: @" %d %@ " , likes, likesWord];
1046
+ _likesLabel.text = [NSString stringWithFormat: @" %lu %@ " , ( unsigned long ) likes, likesWord];
1021
1047
} else {
1022
1048
_likesLabel.text = @" 0 likes" ;
1023
1049
}
@@ -1041,6 +1067,17 @@ - (CGRect)frameForPagingScrollView {
1041
1067
return CGRectIntegral (frame);
1042
1068
}
1043
1069
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
+
1044
1081
- (CGRect)frameForLikesContainer {
1045
1082
CGFloat containerWidth = 120 ;
1046
1083
CGFloat containerHeight = 40 ;
@@ -1734,6 +1771,73 @@ - (void)likeButtonPressed {
1734
1771
[_fullscreenPhotoDelegate isLiked: _currentPageIndex];
1735
1772
}
1736
1773
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
+
1737
1841
#pragma mark - Action Progress
1738
1842
1739
1843
- (MBProgressHUD *)progressHUD {
0 commit comments