diff --git a/Classes/IDMPhotoBrowser.h b/Classes/IDMPhotoBrowser.h index 6fea898c..44cd4ecd 100644 --- a/Classes/IDMPhotoBrowser.h +++ b/Classes/IDMPhotoBrowser.h @@ -5,6 +5,7 @@ // Created by Michael Waterfall on 14/10/2010. // Copyright 2010 d3i. All rights reserved. // +// Modified by Michael Stawarz on 23/11/2015 #import #import @@ -12,8 +13,9 @@ #import "IDMPhoto.h" #import "IDMPhotoProtocol.h" #import "IDMCaptionView.h" +#import "IDMZoomingScrollView.h" -// Delgate +// Delegate @class IDMPhotoBrowser; @protocol IDMPhotoBrowserDelegate @optional @@ -22,10 +24,11 @@ - (void)photoBrowser:(IDMPhotoBrowser *)photoBrowser willDismissAtPageIndex:(NSUInteger)index; - (void)photoBrowser:(IDMPhotoBrowser *)photoBrowser didDismissActionSheetWithButtonIndex:(NSUInteger)buttonIndex photoIndex:(NSUInteger)photoIndex; - (IDMCaptionView *)photoBrowser:(IDMPhotoBrowser *)photoBrowser captionViewForPhotoAtIndex:(NSUInteger)index; +- (void)photoBrowser:(IDMPhotoBrowser *)photoBrowser activityViewControllerActivitySelected:(NSString *)activityType andPhoto:(id)photo; @end // IDMPhotoBrowser -@interface IDMPhotoBrowser : UIViewController +@interface IDMPhotoBrowser : UIViewController // Properties @property (nonatomic, strong) id delegate; diff --git a/Classes/IDMPhotoBrowser.m b/Classes/IDMPhotoBrowser.m index d2f9e935..c0b64778 100644 --- a/Classes/IDMPhotoBrowser.m +++ b/Classes/IDMPhotoBrowser.m @@ -5,11 +5,17 @@ // Created by Michael Waterfall on 14/10/2010. // Copyright 2010 d3i. All rights reserved. // +// Modified for CaptureLife by Michal Stawarz on 20/11/2015 + #import #import "IDMPhotoBrowser.h" #import "IDMZoomingScrollView.h" +#import "SDWebImageDownloader.h" +#import "SDWebImageManager.h" +#import + #import "pop/POP.h" #ifndef IDMPhotoBrowserLocalizedStrings @@ -19,26 +25,28 @@ // Private @interface IDMPhotoBrowser () { - // Data + // Data NSMutableArray *_photos; - // Views - UIScrollView *_pagingScrollView; - + // Views + UIScrollView *_pagingScrollView; + // Gesture UIPanGestureRecognizer *_panGesture; - // Paging + // Paging NSMutableSet *_visiblePages, *_recycledPages; NSUInteger _pageIndexBeforeRotation; NSUInteger _currentPageIndex; - + // Buttons UIButton *_doneButton; + UIButton *_printButton; + BOOL goingToPrint; - // Toolbar - UIToolbar *_toolbar; - UIBarButtonItem *_previousButton, *_nextButton, *_actionButton; + // Toolbar + UIToolbar *_toolbar; + UIBarButtonItem *_previousButton, *_nextButton, *_actionButton; UIBarButtonItem *_counterButton; UILabel *_counterLabel; @@ -51,14 +59,14 @@ @interface IDMPhotoBrowser () { // Appearance //UIStatusBarStyle _previousStatusBarStyle; - BOOL _statusBarOriginallyHidden; + BOOL _statusBarOriginallyHidden; // Present UIView *_senderViewForAnimation; // Misc BOOL _performingLayout; - BOOL _rotating; + BOOL _rotating; BOOL _viewIsActive; // active as in it's in the view heirarchy BOOL _autoHide; NSInteger _initalPageIndex; @@ -69,10 +77,11 @@ @interface IDMPhotoBrowser () { //UIImage *_backgroundScreenshot; UIWindow *_applicationWindow; - - // iOS 7 + + // iOS 7 UIViewController *_applicationTopViewController; int _previousModalPresentationStyle; + } // Private Properties @@ -127,7 +136,9 @@ - (void)releaseAllUnderlyingPhotos; @end // IDMPhotoBrowser -@implementation IDMPhotoBrowser +@implementation IDMPhotoBrowser { + BOOL photoDisplayed; +} // Properties @synthesize displayDoneButton = _displayDoneButton, displayToolbar = _displayToolbar, displayActionButton = _displayActionButton, displayCounterLabel = _displayCounterLabel, useWhiteBackgroundColor = _useWhiteBackgroundColor, doneButtonImage = _doneButtonImage; @@ -141,6 +152,9 @@ @implementation IDMPhotoBrowser @synthesize trackTintColor = _trackTintColor, progressTintColor = _progressTintColor; @synthesize delegate = _delegate; + +int kPrintButtonUnavailableAlphaVal = 0.7; + #pragma mark - NSObject - (id)init { @@ -148,8 +162,8 @@ - (id)init { // Defaults self.hidesBottomBarWhenPushed = YES; _currentPageIndex = 0; - _performingLayout = NO; // Reset on view did appear - _rotating = NO; + _performingLayout = NO; // Reset on view did appear + _rotating = NO; _viewIsActive = NO; _visiblePages = [NSMutableSet new]; _recycledPages = [NSMutableSet new]; @@ -157,6 +171,7 @@ - (id)init { _initalPageIndex = 0; _autoHide = YES; + photoDisplayed = NO; _displayDoneButton = YES; _doneButtonImage = nil; @@ -168,8 +183,8 @@ - (id)init { _forceHideStatusBar = NO; _usePopAnimation = NO; - _disableVerticalSwipe = NO; - + _disableVerticalSwipe = NO; + _useWhiteBackgroundColor = NO; _leftArrowImage = _rightArrowImage = _leftArrowSelectedImage = _rightArrowSelectedImage = nil; @@ -181,28 +196,29 @@ - (id)init { _scaleImage = nil; _isdraggingPhoto = NO; + goingToPrint = NO; if ([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)]) self.automaticallyAdjustsScrollViewInsets = NO; _applicationWindow = [[[UIApplication sharedApplication] delegate] window]; - - if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) - { - self.modalPresentationStyle = UIModalPresentationCustom; - self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; + + if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) + { + self.modalPresentationStyle = UIModalPresentationCustom; + self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; self.modalPresentationCapturesStatusBarAppearance = YES; - } - else - { - _applicationTopViewController = [self topviewController]; - _previousModalPresentationStyle = _applicationTopViewController.modalPresentationStyle; - _applicationTopViewController.modalPresentationStyle = UIModalPresentationCurrentContext; - self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; - } - - self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; - + } + else + { + _applicationTopViewController = [self topviewController]; + _previousModalPresentationStyle = _applicationTopViewController.modalPresentationStyle; + _applicationTopViewController.modalPresentationStyle = UIModalPresentationCurrentContext; + self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; + } + + self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; + // Listen for IDMPhoto notifications [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleIDMPhotoLoadingDidEndNotification:) @@ -215,34 +231,34 @@ - (id)init { - (id)initWithPhotos:(NSArray *)photosArray { if ((self = [self init])) { - _photos = [[NSMutableArray alloc] initWithArray:photosArray]; - } - return self; + _photos = [[NSMutableArray alloc] initWithArray:photosArray]; + } + return self; } - (id)initWithPhotos:(NSArray *)photosArray animatedFromView:(UIView*)view { if ((self = [self init])) { - _photos = [[NSMutableArray alloc] initWithArray:photosArray]; + _photos = [[NSMutableArray alloc] initWithArray:photosArray]; _senderViewForAnimation = view; - } - return self; + } + return self; } - (id)initWithPhotoURLs:(NSArray *)photoURLsArray { if ((self = [self init])) { NSArray *photosArray = [IDMPhoto photosWithURLs:photoURLsArray]; - _photos = [[NSMutableArray alloc] initWithArray:photosArray]; - } - return self; + _photos = [[NSMutableArray alloc] initWithArray:photosArray]; + } + return self; } - (id)initWithPhotoURLs:(NSArray *)photoURLsArray animatedFromView:(UIView*)view { if ((self = [self init])) { NSArray *photosArray = [IDMPhoto photosWithURLs:photoURLsArray]; - _photos = [[NSMutableArray alloc] initWithArray:photosArray]; + _photos = [[NSMutableArray alloc] initWithArray:photosArray]; _senderViewForAnimation = view; - } - return self; + } + return self; } - (void)dealloc { @@ -256,11 +272,11 @@ - (void)releaseAllUnderlyingPhotos { } - (void)didReceiveMemoryWarning { - // Release any cached data, images, etc that aren't in use. + // Release any cached data, images, etc that aren't in use. [self releaseAllUnderlyingPhotos]; - [_recycledPages removeAllObjects]; - - // Releases the view if it doesn't have a superview. + [_recycledPages removeAllObjects]; + + // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; } @@ -505,18 +521,18 @@ - (void)prepareForClosePhotoBrowser { - (void)dismissPhotoBrowserAnimated:(BOOL)animated { self.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; - + if ([_delegate respondsToSelector:@selector(photoBrowser:willDismissAtPageIndex:)]) [_delegate photoBrowser:self willDismissAtPageIndex:_currentPageIndex]; [self dismissViewControllerAnimated:animated completion:^{ if ([_delegate respondsToSelector:@selector(photoBrowser:didDismissAtPageIndex:)]) [_delegate photoBrowser:self didDismissAtPageIndex:_currentPageIndex]; - - if (SYSTEM_VERSION_LESS_THAN(@"8.0")) - { - _applicationTopViewController.modalPresentationStyle = _previousModalPresentationStyle; - } + + if (SYSTEM_VERSION_LESS_THAN(@"8.0")) + { + _applicationTopViewController.modalPresentationStyle = _previousModalPresentationStyle; + } }]; } @@ -553,21 +569,21 @@ - (UIViewController *)topviewController - (void)viewDidLoad { // View - self.view.backgroundColor = [UIColor colorWithWhite:(_useWhiteBackgroundColor ? 1 : 0) alpha:1]; + self.view.backgroundColor = [UIColor colorWithWhite:(_useWhiteBackgroundColor ? 1 : 0) alpha:1]; self.view.clipsToBounds = YES; - // Setup paging scrolling view - CGRect pagingScrollViewFrame = [self frameForPagingScrollView]; - _pagingScrollView = [[UIScrollView alloc] initWithFrame:pagingScrollViewFrame]; + // Setup paging scrolling view + CGRect pagingScrollViewFrame = [self frameForPagingScrollView]; + _pagingScrollView = [[UIScrollView alloc] initWithFrame:pagingScrollViewFrame]; //_pagingScrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - _pagingScrollView.pagingEnabled = YES; - _pagingScrollView.delegate = self; - _pagingScrollView.showsHorizontalScrollIndicator = NO; - _pagingScrollView.showsVerticalScrollIndicator = NO; - _pagingScrollView.backgroundColor = [UIColor clearColor]; + _pagingScrollView.pagingEnabled = YES; + _pagingScrollView.delegate = self; + _pagingScrollView.showsHorizontalScrollIndicator = NO; + _pagingScrollView.showsVerticalScrollIndicator = NO; + _pagingScrollView.backgroundColor = [UIColor clearColor]; _pagingScrollView.contentSize = [self contentSizeForPagingScrollView]; - [self.view addSubview:_pagingScrollView]; + [self.view addSubview:_pagingScrollView]; // Transition animation [self performPresentAnimation]; @@ -603,6 +619,23 @@ - (void)viewDidLoad { _doneButton.contentMode = UIViewContentModeScaleAspectFit; } + // Print Button + _printButton = [UIButton buttonWithType:UIButtonTypeCustom]; + [_printButton setFrame:[self frameForPrintButtonAtOrientation:currentOrientation]]; + [_printButton setAlpha:1.0f]; + [_printButton addTarget:self action:@selector(printButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; + + // if(!_doneButtonImage) { + [_printButton setTitleColor:[UIColor colorWithWhite:0.9 alpha:0.9] forState:UIControlStateNormal|UIControlStateHighlighted]; + [_printButton setTitle:IDMPhotoBrowserLocalizedStrings(@"Print") forState:UIControlStateNormal]; + [_printButton.titleLabel setFont:[UIFont boldSystemFontOfSize:11.0f]]; + [_printButton setBackgroundColor:[UIColor colorWithWhite:0.1 alpha:0.5]]; + _printButton.layer.cornerRadius = 3.0f; + _printButton.layer.borderColor = [UIColor colorWithWhite:0.9 alpha:0.9].CGColor; + _printButton.layer.borderWidth = 1.0f; + + + UIImage *leftButtonImage = (_leftArrowImage == nil) ? [UIImage imageNamed:@"IDMPhotoBrowser.bundle/images/IDMPhotoBrowser_arrowLeft.png"] : _leftArrowImage; @@ -655,22 +688,42 @@ - (void)viewDidLoad { // Update //[self reloadData]; - // Super + // Super [super viewDidLoad]; } +- (void)viewWillDisappear:(BOOL)animated { + + // !!! + // SUPER IMPORTANT + // !!! + if (!goingToPrint) { + SDWebImageDownloader *manager = [SDWebImageManager sharedManager].imageDownloader; + [manager setValue:[NSString stringWithFormat:@"Token %@", [[NSUserDefaults standardUserDefaults] stringForKey:@"user-defaults-token"]] forHTTPHeaderField:@"Authorization"]; + } + // !!! + // SUPER IMPORTANT + // !!! + +} + - (void)viewWillAppear:(BOOL)animated { + // Make sure the authorisation token is there + SDWebImageDownloader *manager = [SDWebImageManager sharedManager].imageDownloader; + [manager setValue:[NSString stringWithFormat:@"Token %@", [[NSUserDefaults standardUserDefaults] stringForKey:@"user-defaults-token"]] forHTTPHeaderField:@"Authorization"]; + goingToPrint = NO; + // Update [self reloadData]; // Super - [super viewWillAppear:animated]; + [super viewWillAppear:animated]; // Status Bar _statusBarOriginallyHidden = [UIApplication sharedApplication].statusBarHidden; // Update UI - [self hideControlsAfterDelay]; + [self hideControlsAfterDelay]; } - (void)viewDidAppear:(BOOL)animated { @@ -680,12 +733,13 @@ - (void)viewDidAppear:(BOOL)animated { // Release any retained subviews of the main view. - (void)viewDidUnload { - _currentPageIndex = 0; + _currentPageIndex = 0; _pagingScrollView = nil; _visiblePages = nil; _recycledPages = nil; _toolbar = nil; _doneButton = nil; + _printButton = nil; _previousButton = nil; _nextButton = nil; @@ -717,14 +771,14 @@ - (BOOL)prefersStatusBarHidden { } - (UIStatusBarAnimation)preferredStatusBarUpdateAnimation { - return UIStatusBarAnimationFade; + return UIStatusBarAnimationFade; } #pragma mark - Layout - (void)viewWillLayoutSubviews { - // Flag - _performingLayout = YES; + // Flag + _performingLayout = YES; UIInterfaceOrientation currentOrientation = [UIApplication sharedApplication].statusBarOrientation; @@ -733,35 +787,35 @@ - (void)viewWillLayoutSubviews { // Done button _doneButton.frame = [self frameForDoneButtonAtOrientation:currentOrientation]; - + _printButton.frame = [self frameForPrintButtonAtOrientation:currentOrientation]; // Remember index - NSUInteger indexPriorToLayout = _currentPageIndex; - - // Get paging scroll view frame to determine if anything needs changing - CGRect pagingScrollViewFrame = [self frameForPagingScrollView]; - - // Frame needs changing - _pagingScrollView.frame = pagingScrollViewFrame; - - // Recalculate contentSize based on current orientation - _pagingScrollView.contentSize = [self contentSizeForPagingScrollView]; - - // Adjust frames and configuration of each visible page - for (IDMZoomingScrollView *page in _visiblePages) { + NSUInteger indexPriorToLayout = _currentPageIndex; + + // Get paging scroll view frame to determine if anything needs changing + CGRect pagingScrollViewFrame = [self frameForPagingScrollView]; + + // Frame needs changing + _pagingScrollView.frame = pagingScrollViewFrame; + + // Recalculate contentSize based on current orientation + _pagingScrollView.contentSize = [self contentSizeForPagingScrollView]; + + // Adjust frames and configuration of each visible page + for (IDMZoomingScrollView *page in _visiblePages) { NSUInteger index = PAGE_INDEX(page); - page.frame = [self frameForPageAtIndex:index]; + page.frame = [self frameForPageAtIndex:index]; page.captionView.frame = [self frameForCaptionView:page.captionView atIndex:index]; - [page setMaxMinZoomScalesForCurrentBounds]; - } - - // Adjust contentOffset to preserve page location based on values collected prior to location - _pagingScrollView.contentOffset = [self contentOffsetForPageAtIndex:indexPriorToLayout]; - [self didStartViewingPageAtIndex:_currentPageIndex]; // initial + [page setMaxMinZoomScalesForCurrentBounds]; + } - // Reset - _currentPageIndex = indexPriorToLayout; - _performingLayout = NO; + // Adjust contentOffset to preserve page location based on values collected prior to location + _pagingScrollView.contentOffset = [self contentOffsetForPageAtIndex:indexPriorToLayout]; + [self didStartViewingPageAtIndex:_currentPageIndex]; // initial + + // Reset + _currentPageIndex = indexPriorToLayout; + _performingLayout = NO; // Super [super viewWillLayoutSubviews]; @@ -772,7 +826,7 @@ - (void)performLayout { _performingLayout = YES; NSUInteger numberOfPhotos = [self numberOfPhotos]; - // Setup pages + // Setup pages [_visiblePages removeAllObjects]; [_recycledPages removeAllObjects]; @@ -787,6 +841,8 @@ - (void)performLayout { if(_displayDoneButton && !self.navigationController.navigationBar) [self.view addSubview:_doneButton]; + [self.view addSubview:_printButton]; + // Toolbar items & navigation UIBarButtonItem *fixedLeftSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil]; @@ -816,15 +872,15 @@ - (void)performLayout { [items addObject:_actionButton]; [_toolbar setItems:items]; - [self updateToolbar]; + [self updateToolbar]; // Content offset - _pagingScrollView.contentOffset = [self contentOffsetForPageAtIndex:_currentPageIndex]; + _pagingScrollView.contentOffset = [self contentOffsetForPageAtIndex:_currentPageIndex]; [self tilePages]; _performingLayout = NO; - - if(! _disableVerticalSwipe) - [self.view addGestureRecognizer:_panGesture]; + + if(! _disableVerticalSwipe) + [self.view addGestureRecognizer:_panGesture]; } #pragma mark - Data @@ -864,19 +920,19 @@ - (IDMCaptionView *)captionViewForPhotoAtIndex:(NSUInteger)index { } - (UIImage *)imageForPhoto:(id)photo { - if (photo) { - // Get image or obtain in background - if ([photo underlyingImage]) { - return [photo underlyingImage]; - } else { + if (photo) { + // Get image or obtain in background + if ([photo underlyingImage]) { + return [photo underlyingImage]; + } else { [photo loadUnderlyingImageAndNotify]; if ([photo respondsToSelector:@selector(placeholderImage)]) { return [photo placeholderImage]; } - } - } + } + } - return nil; + return nil; } - (void)loadAdjacentPhotosIfNecessary:(id)photo { @@ -925,99 +981,123 @@ - (void)handleIDMPhotoLoadingDidEndNotification:(NSNotification *)notification { #pragma mark - Paging - (void)tilePages { - // Calculate which pages should be visible - // Ignore padding as paging bounces encroach on that - // and lead to false page loads - CGRect visibleBounds = _pagingScrollView.bounds; - NSInteger iFirstIndex = (NSInteger) floorf((CGRectGetMinX(visibleBounds)+PADDING*2) / CGRectGetWidth(visibleBounds)); - NSInteger iLastIndex = (NSInteger) floorf((CGRectGetMaxX(visibleBounds)-PADDING*2-1) / CGRectGetWidth(visibleBounds)); + // Calculate which pages should be visible + // Ignore padding as paging bounces encroach on that + // and lead to false page loads + CGRect visibleBounds = _pagingScrollView.bounds; + NSInteger iFirstIndex = (NSInteger) floorf((CGRectGetMinX(visibleBounds)+PADDING*2) / CGRectGetWidth(visibleBounds)); + NSInteger iLastIndex = (NSInteger) floorf((CGRectGetMaxX(visibleBounds)-PADDING*2-1) / CGRectGetWidth(visibleBounds)); if (iFirstIndex < 0) iFirstIndex = 0; if (iFirstIndex > [self numberOfPhotos] - 1) iFirstIndex = [self numberOfPhotos] - 1; if (iLastIndex < 0) iLastIndex = 0; if (iLastIndex > [self numberOfPhotos] - 1) iLastIndex = [self numberOfPhotos] - 1; - - // Recycle no longer needed pages + + // Recycle no longer needed pages NSInteger pageIndex; - for (IDMZoomingScrollView *page in _visiblePages) { + for (IDMZoomingScrollView *page in _visiblePages) { pageIndex = PAGE_INDEX(page); - if (pageIndex < (NSUInteger)iFirstIndex || pageIndex > (NSUInteger)iLastIndex) { - [_recycledPages addObject:page]; + if (pageIndex < (NSUInteger)iFirstIndex || pageIndex > (NSUInteger)iLastIndex) { + [_recycledPages addObject:page]; [page prepareForReuse]; - [page removeFromSuperview]; - IDMLog(@"Removed page at index %i", PAGE_INDEX(page)); - } - } - [_visiblePages minusSet:_recycledPages]; + [page removeFromSuperview]; + IDMLog(@"Removed page at index %i", PAGE_INDEX(page)); + } + } + [_visiblePages minusSet:_recycledPages]; while (_recycledPages.count > 2) // Only keep 2 recycled pages [_recycledPages removeObject:[_recycledPages anyObject]]; - - // Add missing pages - for (NSUInteger index = (NSUInteger)iFirstIndex; index <= (NSUInteger)iLastIndex; index++) { - if (![self isDisplayingPageForIndex:index]) { + + // Add missing pages + for (NSUInteger index = (NSUInteger)iFirstIndex; index <= (NSUInteger)iLastIndex; index++) { + if (![self isDisplayingPageForIndex:index]) { // Add new page - IDMZoomingScrollView *page; + IDMZoomingScrollView *page; page = [[IDMZoomingScrollView alloc] initWithPhotoBrowser:self]; + page.photoLoadingDelegate = self; page.backgroundColor = [UIColor clearColor]; page.opaque = YES; - [self configurePage:page forIndex:index]; - [_visiblePages addObject:page]; - [_pagingScrollView addSubview:page]; - IDMLog(@"Added page at index %i", index); + [self configurePage:page forIndex:index]; + [_visiblePages addObject:page]; + [_pagingScrollView addSubview:page]; + IDMLog(@"Added page at index %i", index); // Add caption IDMCaptionView *captionView = [self captionViewForPhotoAtIndex:index]; captionView.frame = [self frameForCaptionView:captionView atIndex:index]; [_pagingScrollView addSubview:captionView]; page.captionView = captionView; - } - } + } + } } - (BOOL)isDisplayingPageForIndex:(NSUInteger)index { - for (IDMZoomingScrollView *page in _visiblePages) - if (PAGE_INDEX(page) == index) return YES; - return NO; + for (IDMZoomingScrollView *page in _visiblePages) + if (PAGE_INDEX(page) == index) return YES; + return NO; } - (IDMZoomingScrollView *)pageDisplayedAtIndex:(NSUInteger)index { - IDMZoomingScrollView *thePage = nil; - for (IDMZoomingScrollView *page in _visiblePages) { - if (PAGE_INDEX(page) == index) { - thePage = page; break; - } - } - return thePage; + IDMZoomingScrollView *thePage = nil; + for (IDMZoomingScrollView *page in _visiblePages) { + if (PAGE_INDEX(page) == index) { + thePage = page; break; + } + } + return thePage; } - (IDMZoomingScrollView *)pageDisplayingPhoto:(id)photo { - IDMZoomingScrollView *thePage = nil; - for (IDMZoomingScrollView *page in _visiblePages) { - if (page.photo == photo) { - thePage = page; break; - } - } - return thePage; + IDMZoomingScrollView *thePage = nil; + for (IDMZoomingScrollView *page in _visiblePages) { + if (page.photo == photo) { + thePage = page; break; + } + } + return thePage; +} + +- (void)pictureDidLoad:(IDMPhoto *)photo { + // NSLog(@"Picture did appear %@", photo); + + [UIView animateWithDuration:0.66 animations:^{ + [_printButton setAlpha:_doneButton.alpha]; + } completion:^(BOOL finished) { + [_printButton setUserInteractionEnabled:YES]; + photoDisplayed = YES; + }]; + } - (void)configurePage:(IDMZoomingScrollView *)page forIndex:(NSUInteger)index { - page.frame = [self frameForPageAtIndex:index]; + page.frame = [self frameForPageAtIndex:index]; page.tag = PAGE_INDEX_TAG_OFFSET + index; page.photo = [self photoAtIndex:index]; + // NSLog(@"configurePage"); + if (!page.photo.underlyingImage) { + photoDisplayed = NO; + [_printButton setUserInteractionEnabled:NO]; + [UIView animateWithDuration:0.25 animations:^{ + [_printButton setAlpha:kPrintButtonUnavailableAlphaVal]; + }]; + } + + __block __weak IDMPhoto *photo = (IDMPhoto*)page.photo; __weak IDMZoomingScrollView* weakPage = page; photo.progressUpdateBlock = ^(CGFloat progress){ + NSLog(@"%f", progress); [weakPage setProgress:progress forPhoto:photo]; }; } - (IDMZoomingScrollView *)dequeueRecycledPage { - IDMZoomingScrollView *page = [_recycledPages anyObject]; - if (page) { - [_recycledPages removeObject:page]; - } - return page; + IDMZoomingScrollView *page = [_recycledPages anyObject]; + if (page) { + [_recycledPages removeObject:page]; + } + return page; } // Handle page changes @@ -1029,6 +1109,7 @@ - (void)didStartViewingPageAtIndex:(NSUInteger)index { // photo loaded so load ajacent now [self loadAdjacentPhotosIfNecessary:currentPhoto]; } + if ([_delegate respondsToSelector:@selector(photoBrowser:didShowPhotoAtIndex:)]) { [_delegate photoBrowser:self didShowPhotoAtIndex:index]; } @@ -1062,9 +1143,9 @@ - (CGSize)contentSizeForPagingScrollView { } - (CGPoint)contentOffsetForPageAtIndex:(NSUInteger)index { - CGFloat pageWidth = _pagingScrollView.bounds.size.width; - CGFloat newOffset = index * pageWidth; - return CGPointMake(newOffset, 0); + CGFloat pageWidth = _pagingScrollView.bounds.size.width; + CGFloat newOffset = index * pageWidth; + return CGPointMake(newOffset, 0); } - (BOOL)isLandscape:(UIInterfaceOrientation)orientation @@ -1089,6 +1170,14 @@ - (CGRect)frameForDoneButtonAtOrientation:(UIInterfaceOrientation)orientation { return CGRectMake(screenWidth - 75, 30, 55, 26); } +- (CGRect)frameForPrintButtonAtOrientation:(UIInterfaceOrientation)orientation { + CGRect screenBound = self.view.bounds; + CGFloat screenWidth = screenBound.size.width; + + // if ([self isLandscape:orientation]) screenWidth = screenBound.size.height; + + return CGRectMake(25, 30, 55, 26); +} - (CGRect)frameForCaptionView:(IDMCaptionView *)captionView atIndex:(NSUInteger)index { CGRect pageFrame = [self frameForPageAtIndex:index]; @@ -1123,36 +1212,37 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView { } - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { - // Hide controls when dragging begins - [self setControlsHidden:YES animated:YES permanent:NO]; + // Hide controls when dragging begins + [self setControlsHidden:YES animated:YES permanent:NO]; } - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { - // Update toolbar when page changes - if(! _arrowButtonsChangePhotosAnimated) [self updateToolbar]; + // Update toolbar when page changes + if(! _arrowButtonsChangePhotosAnimated) [self updateToolbar]; + } #pragma mark - Toolbar - (void)updateToolbar { // Counter - if ([self numberOfPhotos] > 1) { - _counterLabel.text = [NSString stringWithFormat:@"%lu %@ %lu", (unsigned long)(_currentPageIndex+1), IDMPhotoBrowserLocalizedStrings(@"of"), (unsigned long)[self numberOfPhotos]]; - } else { - _counterLabel.text = nil; - } + if ([self numberOfPhotos] > 1) { + _counterLabel.text = [NSString stringWithFormat:@"%lu %@ %lu", (unsigned long)(_currentPageIndex+1), IDMPhotoBrowserLocalizedStrings(@"of"), (unsigned long)[self numberOfPhotos]]; + } else { + _counterLabel.text = nil; + } - // Buttons - _previousButton.enabled = (_currentPageIndex > 0); - _nextButton.enabled = (_currentPageIndex < [self numberOfPhotos]-1); + // Buttons + _previousButton.enabled = (_currentPageIndex > 0); + _nextButton.enabled = (_currentPageIndex < [self numberOfPhotos]-1); } - (void)jumpToPageAtIndex:(NSUInteger)index { // Change page - if (index < [self numberOfPhotos]) { - CGRect pageFrame = [self frameForPageAtIndex:index]; + if (index < [self numberOfPhotos]) { + CGRect pageFrame = [self frameForPageAtIndex:index]; - if(_arrowButtonsChangePhotosAnimated) + if(_arrowButtonsChangePhotosAnimated) { [_pagingScrollView setContentOffset:CGPointMake(pageFrame.origin.x - PADDING, 0) animated:YES]; } @@ -1161,10 +1251,10 @@ - (void)jumpToPageAtIndex:(NSUInteger)index { _pagingScrollView.contentOffset = CGPointMake(pageFrame.origin.x - PADDING, 0); [self updateToolbar]; } - } - - // Update timer to give more time - [self hideControlsAfterDelay]; + } + + // Update timer to give more time + [self hideControlsAfterDelay]; } - (void)gotoPreviousPage { [self jumpToPageAtIndex:_currentPageIndex-1]; } @@ -1187,34 +1277,45 @@ - (void)setControlsHidden:(BOOL)hidden animated:(BOOL)animated permanent:(BOOL)p [UIView animateWithDuration:(animated ? 0.1 : 0) animations:^(void) { CGFloat alpha = hidden ? 0 : 1; [self.navigationController.navigationBar setAlpha:alpha]; + + for (UIView *v in captionViews) v.alpha = alpha; [_toolbar setAlpha:alpha]; [_doneButton setAlpha:alpha]; - for (UIView *v in captionViews) v.alpha = alpha; + if (alpha != 0) { + if (photoDisplayed) { + [_printButton setAlpha:alpha]; + } else { + [_printButton setAlpha:kPrintButtonUnavailableAlphaVal]; + } + } else { + [_printButton setAlpha:alpha]; + } + } completion:^(BOOL finished) {}]; - // Control hiding timer - // Will cancel existing timer but only begin hiding if they are visible - if (!permanent) [self hideControlsAfterDelay]; + // Control hiding timer + // Will cancel existing timer but only begin hiding if they are visible + if (!permanent) [self hideControlsAfterDelay]; [self setNeedsStatusBarAppearanceUpdate]; } - (void)cancelControlHiding { - // If a timer exists then cancel and release - if (_controlVisibilityTimer) { - [_controlVisibilityTimer invalidate]; - _controlVisibilityTimer = nil; - } + // If a timer exists then cancel and release + if (_controlVisibilityTimer) { + [_controlVisibilityTimer invalidate]; + _controlVisibilityTimer = nil; + } } // Enable/disable control visiblity timer - (void)hideControlsAfterDelay { - // return; + // return; if (![self areControlsHidden]) { [self cancelControlHiding]; - _controlVisibilityTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(hideControls) userInfo:nil repeats:NO]; - } + _controlVisibilityTimer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(hideControls) userInfo:nil repeats:NO]; + } } - (BOOL)areControlsHidden { return (_toolbar.alpha == 0); } @@ -1229,7 +1330,7 @@ - (void)setInitialPageIndex:(NSUInteger)index { if (index >= [self numberOfPhotos]) index = [self numberOfPhotos]-1; _initalPageIndex = index; _currentPageIndex = index; - if ([self isViewLoaded]) { + if ([self isViewLoaded]) { [self jumpToPageAtIndex:index]; if (!_viewIsActive) [self tilePages]; // Force tiling if view is not visible } @@ -1249,6 +1350,29 @@ - (void)doneButtonPressed:(id)sender { } } +- (void)printButtonPressed:(id)sender { + + SDWebImageDownloader *manager = [SDWebImageManager sharedManager].imageDownloader; + [manager setValue:@"" forHTTPHeaderField:@"Authorization"]; + goingToPrint = YES; + +#ifdef DEBUG + [OLKitePrintSDK setAPIKey:[[NSUserDefaults standardUserDefaults] stringForKey:@"kite-api-sandbox"] withEnvironment:kOLKitePrintSDKEnvironmentSandbox]; +#else + [OLKitePrintSDK setAPIKey:[[NSUserDefaults standardUserDefaults] stringForKey:@"kite-api-live"] withEnvironment:kOLKitePrintSDKEnvironmentLive]; +#endif + + id photo = [self photoAtIndex:_currentPageIndex]; + OLKiteViewController *vc; + vc.userEmail = @""; + vc.userPhone = @""; + + if ([photo underlyingImage]) { + vc = [[OLKiteViewController alloc] initWithAssets:@[[OLAsset assetWithImageAsPNG:[photo underlyingImage]]]]; + [self presentViewController:vc animated:YES completion:NULL]; + } +} + - (void)actionButtonPressed:(id)sender { id photo = [self photoAtIndex:_currentPageIndex]; @@ -1262,22 +1386,24 @@ - (void)actionButtonPressed:(id)sender { self.activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil]; __typeof__(self) __weak selfBlock = self; - - if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) - { - [self.activityViewController setCompletionWithItemsHandler:^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) { - [selfBlock hideControlsAfterDelay]; - selfBlock.activityViewController = nil; - }]; - } - else - { - [self.activityViewController setCompletionHandler:^(NSString *activityType, BOOL completed) { - [selfBlock hideControlsAfterDelay]; - selfBlock.activityViewController = nil; - }]; - } - + + if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) + { + [self.activityViewController setCompletionWithItemsHandler:^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) { + [selfBlock hideControlsAfterDelay]; + selfBlock.activityViewController = nil; + [_delegate photoBrowser:self activityViewControllerActivitySelected:activityType andPhoto:_photos[_currentPageIndex]]; + }]; + } + else + { + [self.activityViewController setCompletionHandler:^(NSString *activityType, BOOL completed) { + [selfBlock hideControlsAfterDelay]; + selfBlock.activityViewController = nil; + [_delegate photoBrowser:self activityViewControllerActivitySelected:activityType andPhoto:_photos[_currentPageIndex]]; + }]; + } + [self presentViewController:self.activityViewController animated:YES completion:nil]; } else @@ -1325,18 +1451,18 @@ - (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSIn - (void)animateView:(UIView *)view toFrame:(CGRect)frame completion:(void (^)(void))completion { - POPSpringAnimation *animation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewFrame]; - [animation setSpringBounciness:6]; - [animation setDynamicsMass:1]; + POPSpringAnimation *animation = [POPSpringAnimation animationWithPropertyNamed:kPOPViewFrame]; + [animation setSpringBounciness:6]; + [animation setDynamicsMass:1]; [animation setToValue:[NSValue valueWithCGRect:frame]]; - [view pop_addAnimation:animation forKey:nil]; + [view pop_addAnimation:animation forKey:nil]; if (completion) - { - [animation setCompletionBlock:^(POPAnimation *animation, BOOL finished) { - completion(); - }]; - } + { + [animation setCompletionBlock:^(POPAnimation *animation, BOOL finished) { + completion(); + }]; + } } @end diff --git a/Classes/IDMZoomingScrollView.h b/Classes/IDMZoomingScrollView.h index 3393ec43..3b560675 100644 --- a/Classes/IDMZoomingScrollView.h +++ b/Classes/IDMZoomingScrollView.h @@ -5,6 +5,7 @@ // Created by Michael Waterfall on 14/10/2010. // Copyright 2010 d3i. All rights reserved. // +// Modified by Michael Stawarz on 23/11/2015 #import #import "IDMPhotoProtocol.h" @@ -12,18 +13,23 @@ #import "IDMTapDetectingView.h" #import - @class IDMPhotoBrowser, IDMPhoto, IDMCaptionView; +@protocol IDMZoomingScrollViewDelegate + +- (void)pictureDidLoad:(IDMPhoto *) photo; + +@end + @interface IDMZoomingScrollView : UIScrollView { - - IDMPhotoBrowser *__weak _photoBrowser; + + IDMPhotoBrowser *__weak _photoBrowser; id _photo; - + // This view references the related caption view for simplified handling in photo browser IDMCaptionView *_captionView; - IDMTapDetectingView *_tapView; // for background taps + IDMTapDetectingView *_tapView; // for background taps DACircularProgressView *_progressView; } @@ -31,6 +37,7 @@ @property (nonatomic, strong) IDMTapDetectingImageView *photoImageView; @property (nonatomic, strong) IDMCaptionView *captionView; @property (nonatomic, strong) id photo; +@property (nonatomic, strong) id photoLoadingDelegate; - (id)initWithPhotoBrowser:(IDMPhotoBrowser *)browser; - (void)displayImage; diff --git a/Classes/IDMZoomingScrollView.m b/Classes/IDMZoomingScrollView.m index 343031e4..41090527 100644 --- a/Classes/IDMZoomingScrollView.m +++ b/Classes/IDMZoomingScrollView.m @@ -5,6 +5,7 @@ // Created by Michael Waterfall on 14/10/2010. // Copyright 2010 d3i. All rights reserved. // +// Modified by Michael Stawarz on 23/11/2015 #import "IDMZoomingScrollView.h" #import "IDMPhotoBrowser.h" @@ -34,18 +35,18 @@ - (id)initWithPhotoBrowser:(IDMPhotoBrowser *)browser { // Delegate self.photoBrowser = browser; - // Tap view for background - _tapView = [[IDMTapDetectingView alloc] initWithFrame:self.bounds]; - _tapView.tapDelegate = self; - _tapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - _tapView.backgroundColor = [UIColor clearColor]; - [self addSubview:_tapView]; + // Tap view for background + _tapView = [[IDMTapDetectingView alloc] initWithFrame:self.bounds]; + _tapView.tapDelegate = self; + _tapView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + _tapView.backgroundColor = [UIColor clearColor]; + [self addSubview:_tapView]; - // Image view - _photoImageView = [[IDMTapDetectingImageView alloc] initWithFrame:CGRectZero]; - _photoImageView.tapDelegate = self; - _photoImageView.backgroundColor = [UIColor clearColor]; - [self addSubview:_photoImageView]; + // Image view + _photoImageView = [[IDMTapDetectingImageView alloc] initWithFrame:CGRectZero]; + _photoImageView.tapDelegate = self; + _photoImageView.backgroundColor = [UIColor clearColor]; + [self addSubview:_photoImageView]; CGRect screenBound = [[UIScreen mainScreen] bounds]; CGFloat screenWidth = screenBound.size.width; @@ -67,13 +68,13 @@ - (id)initWithPhotoBrowser:(IDMPhotoBrowser *)browser { _progressView.progressTintColor = browser.progressTintColor ? self.photoBrowser.progressTintColor : [UIColor colorWithWhite:1.0 alpha:1]; [self addSubview:_progressView]; - // Setup - self.backgroundColor = [UIColor clearColor]; - self.delegate = self; - self.showsHorizontalScrollIndicator = NO; - self.showsVerticalScrollIndicator = NO; - self.decelerationRate = UIScrollViewDecelerationRateFast; - self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + // Setup + self.backgroundColor = [UIColor clearColor]; + self.delegate = self; + self.showsHorizontalScrollIndicator = NO; + self.showsVerticalScrollIndicator = NO; + self.decelerationRate = UIScrollViewDecelerationRateFast; + self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; } return self; @@ -97,49 +98,51 @@ - (void)prepareForReuse { // Get and display image - (void)displayImage { - if (_photo) { - // Reset - self.maximumZoomScale = 1; - self.minimumZoomScale = 1; - self.zoomScale = 1; + if (_photo) { + // Reset + self.maximumZoomScale = 1; + self.minimumZoomScale = 1; + self.zoomScale = 1; - self.contentSize = CGSizeMake(0, 0); - - // Get image from browser as it handles ordering of fetching - UIImage *img = [self.photoBrowser imageForPhoto:_photo]; - if (img) { + self.contentSize = CGSizeMake(0, 0); + + // Get image from browser as it handles ordering of fetching + UIImage *img = [self.photoBrowser imageForPhoto:_photo]; + if (img) { // Hide ProgressView //_progressView.alpha = 0.0f; [_progressView removeFromSuperview]; // Set image - _photoImageView.image = img; - _photoImageView.hidden = NO; + _photoImageView.image = img; + _photoImageView.hidden = NO; // Setup photo frame - CGRect photoImageViewFrame; - photoImageViewFrame.origin = CGPointZero; - photoImageViewFrame.size = img.size; + CGRect photoImageViewFrame; + photoImageViewFrame.origin = CGPointZero; + photoImageViewFrame.size = img.size; - _photoImageView.frame = photoImageViewFrame; - self.contentSize = photoImageViewFrame.size; - - // Set zoom to minimum zoom - [self setMaxMinZoomScalesForCurrentBounds]; + _photoImageView.frame = photoImageViewFrame; + self.contentSize = photoImageViewFrame.size; + + // Set zoom to minimum zoom + [self setMaxMinZoomScalesForCurrentBounds]; + + [_photoLoadingDelegate pictureDidLoad:_photo]; } else { - // Hide image view - _photoImageView.hidden = YES; + // Hide image view + _photoImageView.hidden = YES; _progressView.alpha = 1.0f; - } + } - [self setNeedsLayout]; - } + [self setNeedsLayout]; + } } - (void)setProgress:(CGFloat)progress forPhoto:(IDMPhoto*)photo { IDMPhoto *p = (IDMPhoto*)self.photo; - + if ([photo.photoURL.absoluteString isEqualToString:p.photoURL.absoluteString]) { if (_progressView.progress < progress) { [_progressView setProgress:progress animated:YES]; @@ -155,15 +158,15 @@ - (void)displayImageFailure { #pragma mark - Setup - (void)setMaxMinZoomScalesForCurrentBounds { - // Reset - self.maximumZoomScale = 1; - self.minimumZoomScale = 1; - self.zoomScale = 1; + // Reset + self.maximumZoomScale = 1; + self.minimumZoomScale = 1; + self.zoomScale = 1; - // Bail - if (_photoImageView.image == nil) return; + // Bail + if (_photoImageView.image == nil) return; - // Sizes + // Sizes CGSize boundsSize = self.bounds.size; CGSize imageSize = _photoImageView.frame.size; @@ -172,42 +175,42 @@ - (void)setMaxMinZoomScalesForCurrentBounds { CGFloat yScale = boundsSize.height / imageSize.height; // the scale needed to perfectly fit the image height-wise CGFloat minScale = MIN(xScale, yScale); // use minimum of these to allow the image to become fully visible - // If image is smaller than the screen then ensure we show it at - // min scale of 1 - if (xScale > 1 && yScale > 1) { - //minScale = 1.0; - } + // If image is smaller than the screen then ensure we show it at + // min scale of 1 + if (xScale > 1 && yScale > 1) { + //minScale = 1.0; + } - // Calculate Max - CGFloat maxScale = 4.0; // Allow double scale + // Calculate Max + CGFloat maxScale = 4.0; // Allow double scale // on high resolution screens we have double the pixel density, so we will be seeing every pixel if we limit the // maximum zoom scale to 0.5. - if ([UIScreen instancesRespondToSelector:@selector(scale)]) { - maxScale = maxScale / [[UIScreen mainScreen] scale]; - - if (maxScale < minScale) { - maxScale = minScale * 2; - } - } + if ([UIScreen instancesRespondToSelector:@selector(scale)]) { + maxScale = maxScale / [[UIScreen mainScreen] scale]; + + if (maxScale < minScale) { + maxScale = minScale * 2; + } + } - // Set - self.maximumZoomScale = maxScale; - self.minimumZoomScale = minScale; - self.zoomScale = minScale; + // Set + self.maximumZoomScale = maxScale; + self.minimumZoomScale = minScale; + self.zoomScale = minScale; - // Reset position - _photoImageView.frame = CGRectMake(0, 0, _photoImageView.frame.size.width, _photoImageView.frame.size.height); - [self setNeedsLayout]; + // Reset position + _photoImageView.frame = CGRectMake(0, 0, _photoImageView.frame.size.width, _photoImageView.frame.size.height); + [self setNeedsLayout]; } #pragma mark - Layout - (void)layoutSubviews { - // Update tap view frame - _tapView.frame = self.bounds; + // Update tap view frame + _tapView.frame = self.bounds; - // Super - [super layoutSubviews]; + // Super + [super layoutSubviews]; // Center the image as it becomes smaller than the size of the screen CGSize boundsSize = self.bounds.size; @@ -216,38 +219,38 @@ - (void)layoutSubviews { // Horizontally if (frameToCenter.size.width < boundsSize.width) { frameToCenter.origin.x = floorf((boundsSize.width - frameToCenter.size.width) / 2.0); - } else { + } else { frameToCenter.origin.x = 0; - } + } // Vertically if (frameToCenter.size.height < boundsSize.height) { frameToCenter.origin.y = floorf((boundsSize.height - frameToCenter.size.height) / 2.0); - } else { + } else { frameToCenter.origin.y = 0; - } + } - // Center - if (!CGRectEqualToRect(_photoImageView.frame, frameToCenter)) - _photoImageView.frame = frameToCenter; + // Center + if (!CGRectEqualToRect(_photoImageView.frame, frameToCenter)) + _photoImageView.frame = frameToCenter; } #pragma mark - UIScrollViewDelegate - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView { - return _photoImageView; + return _photoImageView; } - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView { - [_photoBrowser cancelControlHiding]; + [_photoBrowser cancelControlHiding]; } - (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view { - [_photoBrowser cancelControlHiding]; + [_photoBrowser cancelControlHiding]; } - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { - [_photoBrowser hideControlsAfterDelay]; + [_photoBrowser hideControlsAfterDelay]; } - (void)scrollViewDidZoom:(UIScrollView *)scrollView { @@ -258,33 +261,33 @@ - (void)scrollViewDidZoom:(UIScrollView *)scrollView { #pragma mark - Tap Detection - (void)handleSingleTap:(CGPoint)touchPoint { - [_photoBrowser performSelector:@selector(toggleControls) withObject:nil afterDelay:0.2]; + [_photoBrowser performSelector:@selector(toggleControls) withObject:nil afterDelay:0.2]; } - (void)handleDoubleTap:(CGPoint)touchPoint { - - // Cancel any single tap handling - [NSObject cancelPreviousPerformRequestsWithTarget:_photoBrowser]; - - // Zoom - if (self.zoomScale == self.maximumZoomScale) { - - // Zoom out - [self setZoomScale:self.minimumZoomScale animated:YES]; - - } else { - - // Zoom in - [self zoomToRect:CGRectMake(touchPoint.x, touchPoint.y, 1, 1) animated:YES]; - - } - - // Delay controls - [_photoBrowser hideControlsAfterDelay]; + + // Cancel any single tap handling + [NSObject cancelPreviousPerformRequestsWithTarget:_photoBrowser]; + + // Zoom + if (self.zoomScale == self.maximumZoomScale) { + + // Zoom out + [self setZoomScale:self.minimumZoomScale animated:YES]; + + } else { + + // Zoom in + [self zoomToRect:CGRectMake(touchPoint.x, touchPoint.y, 1, 1) animated:YES]; + + } + + // Delay controls + [_photoBrowser hideControlsAfterDelay]; } // Image View -- (void)imageView:(UIImageView *)imageView singleTapDetected:(UITouch *)touch { +- (void)imageView:(UIImageView *)imageView singleTapDetected:(UITouch *)touch { [self handleSingleTap:[touch locationInView:imageView]]; } - (void)imageView:(UIImageView *)imageView doubleTapDetected:(UITouch *)touch {