From 9a91be7a8b320d0f9eb93938dc213a27e98467f0 Mon Sep 17 00:00:00 2001 From: FAQ_JAMSHED Date: Thu, 29 Jul 2021 20:59:16 +0600 Subject: [PATCH 1/2] - Zoom scale define from outside ; implemented. -Earlier, max zoom scale was 4.0(maximumDoubleTapZoomScale), so if someone wants to zoom more on double click, it was not possible. Now, we can set zoom-in scale value from implementation class. -pod updated - Swift code updated --- Classes/IDMPhotoBrowser.h | 1 + Classes/IDMPhotoBrowser.m | 5 +- Classes/IDMZoomingScrollView.h | 2 +- Classes/IDMZoomingScrollView.m | 22 ++---- .../project.pbxproj | 45 ++--------- Demo/PhotoBrowserDemo/AppDelegate.swift | 2 +- .../AppIcon.appiconset/Contents.json | 79 ++++++++++--------- .../PhotoBrowserDemo/MenuViewController.swift | 13 +-- .../PhotoBrowserDemo-Bridging-Header.h | 2 +- Demo/Podfile.lock | 20 +++-- 10 files changed, 86 insertions(+), 105 deletions(-) diff --git a/Classes/IDMPhotoBrowser.h b/Classes/IDMPhotoBrowser.h index 397a0d4b..dfd1e14b 100644 --- a/Classes/IDMPhotoBrowser.h +++ b/Classes/IDMPhotoBrowser.h @@ -43,6 +43,7 @@ @property (nonatomic, weak) UIImage *leftArrowImage, *leftArrowSelectedImage; @property (nonatomic, weak) UIImage *rightArrowImage, *rightArrowSelectedImage; @property (nonatomic, weak) UIImage *actionButtonImage, *actionButtonSelectedImage; +@property (nonatomic) CGFloat maximumDoubleTapZoomScale; // View customization @property (nonatomic) BOOL displayDoneButton; diff --git a/Classes/IDMPhotoBrowser.m b/Classes/IDMPhotoBrowser.m index 9cd39f32..30b32512 100644 --- a/Classes/IDMPhotoBrowser.m +++ b/Classes/IDMPhotoBrowser.m @@ -81,6 +81,7 @@ @interface IDMPhotoBrowser () { @property (nonatomic, strong) UIActionSheet *actionsSheet; @property (nonatomic, strong) UIActivityViewController *activityViewController; + // Private Methods // Layout @@ -153,7 +154,7 @@ - (id)init { if ((self = [super init])) { // Defaults self.hidesBottomBarWhenPushed = YES; - + _maximumDoubleTapZoomScale = 4; //default _currentPageIndex = 0; _performingLayout = NO; // Reset on view did appear _rotating = NO; @@ -808,6 +809,8 @@ - (void)viewWillLayoutSubviews { NSUInteger index = PAGE_INDEX(page); page.frame = [self frameForPageAtIndex:index]; page.captionView.frame = [self frameForCaptionView:page.captionView atIndex:index]; + page.maximumZoomScale = self.maximumDoubleTapZoomScale; + page.maximumDoubleTapZoomScale = self.maximumDoubleTapZoomScale; [page setMaxMinZoomScalesForCurrentBounds]; } diff --git a/Classes/IDMZoomingScrollView.h b/Classes/IDMZoomingScrollView.h index 9b820be2..274a7383 100644 --- a/Classes/IDMZoomingScrollView.h +++ b/Classes/IDMZoomingScrollView.h @@ -31,7 +31,7 @@ @property (nonatomic, strong) IDMTapDetectingImageView *photoImageView; @property (nonatomic, strong) IDMCaptionView *captionView; @property (nonatomic, strong) id photo; -@property (nonatomic) CGFloat maximumDoubleTapZoomScale; +@property (nonatomic, assign) CGFloat maximumDoubleTapZoomScale; - (id)initWithPhotoBrowser:(IDMPhotoBrowser *)browser; - (void)displayImage; diff --git a/Classes/IDMZoomingScrollView.m b/Classes/IDMZoomingScrollView.m index 754070ed..a78bf1f7 100644 --- a/Classes/IDMZoomingScrollView.m +++ b/Classes/IDMZoomingScrollView.m @@ -118,8 +118,8 @@ - (void)displayImage { // Reset self.maximumZoomScale = 1; self.minimumZoomScale = 1; - self.zoomScale = 1; - + self.zoomScale = 1; + self.contentSize = CGSizeMake(0, 0); // Get image from browser as it handles ordering of fetching @@ -173,11 +173,11 @@ - (void)displayImageFailure { - (void)setMaxMinZoomScalesForCurrentBounds { // Reset - self.maximumZoomScale = 1; + //self.maximumZoomScale = 1; self.minimumZoomScale = 1; self.zoomScale = 1; - - // Bail + + // Bail if (_photoImageView.image == nil) return; // Sizes @@ -199,7 +199,7 @@ - (void)setMaxMinZoomScalesForCurrentBounds { } // Calculate Max - CGFloat maxScale = 4.0; // Allow double scale + CGFloat maxScale = self.maximumDoubleTapZoomScale; //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)]) { @@ -211,7 +211,7 @@ - (void)setMaxMinZoomScalesForCurrentBounds { } // Calculate Max Scale Of Double Tap - CGFloat maxDoubleTapZoomScale = 4.0 * minScale; // Allow double scale + CGFloat maxDoubleTapZoomScale = self.maximumDoubleTapZoomScale * minScale; //4.0 * minScale; // 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)]) { @@ -230,7 +230,7 @@ - (void)setMaxMinZoomScalesForCurrentBounds { self.minimumZoomScale = minScale; self.zoomScale = minScale; self.maximumDoubleTapZoomScale = maxDoubleTapZoomScale; - + // Reset position _photoImageView.frame = CGRectMake(0, 0, _photoImageView.frame.size.width, _photoImageView.frame.size.height); [self setNeedsLayout]; @@ -302,21 +302,15 @@ - (void)handleDoubleTap:(CGPoint)touchPoint { // Cancel any single tap handling [NSObject cancelPreviousPerformRequestsWithTarget:_photoBrowser]; - // Zoom if (self.zoomScale == self.maximumDoubleTapZoomScale) { - // Zoom out [self setZoomScale:self.minimumZoomScale animated:YES]; - } else { - // Zoom in CGSize targetSize = CGSizeMake(self.frame.size.width / self.maximumDoubleTapZoomScale, self.frame.size.height / self.maximumDoubleTapZoomScale); CGPoint targetPoint = CGPointMake(touchPoint.x - targetSize.width / 2, touchPoint.y - targetSize.height / 2); - [self zoomToRect:CGRectMake(targetPoint.x, targetPoint.y, targetSize.width, targetSize.height) animated:YES]; - } // Delay controls diff --git a/Demo/PhotoBrowserDemo.xcodeproj/project.pbxproj b/Demo/PhotoBrowserDemo.xcodeproj/project.pbxproj index 5d9c8df1..67d99881 100644 --- a/Demo/PhotoBrowserDemo.xcodeproj/project.pbxproj +++ b/Demo/PhotoBrowserDemo.xcodeproj/project.pbxproj @@ -92,8 +92,6 @@ 7D2B79BF1FD25B7600F2094F /* PhotoBrowserDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PhotoBrowserDemoTests.m; sourceTree = ""; }; 7D2B79C11FD25B7600F2094F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 7D2B79C71FD25BF300F2094F /* IDMUtilsTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IDMUtilsTest.m; sourceTree = ""; }; - 7D7D66691E09D6D400410A67 /* IDMBrowserDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IDMBrowserDelegate.h; sourceTree = ""; }; - 7D7D666A1E09D6DA00410A67 /* IDMPhotoDataSource.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IDMPhotoDataSource.h; sourceTree = ""; }; D00FA320EEACA8C835D9D626 /* Pods-PhotoBrowserDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-PhotoBrowserDemo.debug.xcconfig"; path = "Pods/Target Support Files/Pods-PhotoBrowserDemo/Pods-PhotoBrowserDemo.debug.xcconfig"; sourceTree = ""; }; D11464B61802FFC4005B7BC3 /* IDMPBConstants.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IDMPBConstants.h; sourceTree = ""; }; D114BB401A32269C00E677FE /* Launch Screen.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = "Launch Screen.xib"; sourceTree = ""; }; @@ -283,7 +281,6 @@ D1574954178DB94900B0211A /* IDMPhotoBrowser.m */, 7D2B79B61FD2501200F2094F /* IDMUtils.h */, 7D2B79B71FD2501200F2094F /* IDMUtils.m */, - 7D7D666A1E09D6DA00410A67 /* IDMPhotoDataSource.h */, D1574955178DB94900B0211A /* IDMPhotoProtocol.h */, D1574956178DB94900B0211A /* IDMTapDetectingImageView.h */, D1574957178DB94900B0211A /* IDMTapDetectingImageView.m */, @@ -327,8 +324,6 @@ 4C6F978914AF734800F8389A /* Sources */, 4C6F978A14AF734800F8389A /* Frameworks */, 4C6F978B14AF734800F8389A /* Resources */, - 64D1E44DFBE2976FB9C75718 /* [CP] Embed Pods Frameworks */, - F88445D630091F1AA9A2F89A /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -380,6 +375,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, fr, pt, @@ -438,49 +434,22 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 64D1E44DFBE2976FB9C75718 /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Embed Pods Frameworks"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-PhotoBrowserDemo/Pods-PhotoBrowserDemo-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; 9FEC6B6CD1E66BC894CF44FA /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", ); name = "[CP] Check Pods Manifest.lock"; outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-PhotoBrowserDemo-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; - showEnvVarsInLog = 0; - }; - F88445D630091F1AA9A2F89A /* [CP] Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Copy Pods Resources"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-PhotoBrowserDemo/Pods-PhotoBrowserDemo-resources.sh\"\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ @@ -621,7 +590,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "PhotoBrowserDemo/PhotoBrowserDemo-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0.1; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; USER_HEADER_SEARCH_PATHS = "../**"; WRAPPER_EXTENSION = app; @@ -645,7 +614,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.appkraft.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "PhotoBrowserDemo/PhotoBrowserDemo-Bridging-Header.h"; - SWIFT_VERSION = 3.0.1; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; USER_HEADER_SEARCH_PATHS = "../**"; WRAPPER_EXTENSION = app; diff --git a/Demo/PhotoBrowserDemo/AppDelegate.swift b/Demo/PhotoBrowserDemo/AppDelegate.swift index 563d9876..202e63e3 100644 --- a/Demo/PhotoBrowserDemo/AppDelegate.swift +++ b/Demo/PhotoBrowserDemo/AppDelegate.swift @@ -17,7 +17,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // MARK: - Application State extension AppDelegate { - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { self.window = UIWindow.init(frame: UIScreen.main.bounds) diff --git a/Demo/PhotoBrowserDemo/Images.xcassets/AppIcon.appiconset/Contents.json b/Demo/PhotoBrowserDemo/Images.xcassets/AppIcon.appiconset/Contents.json index 1d060ed2..9221b9bb 100644 --- a/Demo/PhotoBrowserDemo/Images.xcassets/AppIcon.appiconset/Contents.json +++ b/Demo/PhotoBrowserDemo/Images.xcassets/AppIcon.appiconset/Contents.json @@ -2,92 +2,97 @@ "images" : [ { "idiom" : "iphone", - "size" : "20x20", - "scale" : "2x" + "scale" : "2x", + "size" : "20x20" }, { "idiom" : "iphone", - "size" : "20x20", - "scale" : "3x" + "scale" : "3x", + "size" : "20x20" }, { "idiom" : "iphone", - "size" : "29x29", - "scale" : "2x" + "scale" : "2x", + "size" : "29x29" }, { "idiom" : "iphone", - "size" : "29x29", - "scale" : "3x" + "scale" : "3x", + "size" : "29x29" }, { "idiom" : "iphone", - "size" : "40x40", - "scale" : "2x" + "scale" : "2x", + "size" : "40x40" }, { "idiom" : "iphone", - "size" : "40x40", - "scale" : "3x" + "scale" : "3x", + "size" : "40x40" }, { "idiom" : "iphone", - "size" : "60x60", - "scale" : "2x" + "scale" : "2x", + "size" : "60x60" }, { "idiom" : "iphone", - "size" : "60x60", - "scale" : "3x" + "scale" : "3x", + "size" : "60x60" }, { "idiom" : "ipad", - "size" : "20x20", - "scale" : "1x" + "scale" : "1x", + "size" : "20x20" }, { "idiom" : "ipad", - "size" : "20x20", - "scale" : "2x" + "scale" : "2x", + "size" : "20x20" }, { "idiom" : "ipad", - "size" : "29x29", - "scale" : "1x" + "scale" : "1x", + "size" : "29x29" }, { "idiom" : "ipad", - "size" : "29x29", - "scale" : "2x" + "scale" : "2x", + "size" : "29x29" }, { "idiom" : "ipad", - "size" : "40x40", - "scale" : "1x" + "scale" : "1x", + "size" : "40x40" }, { "idiom" : "ipad", - "size" : "40x40", - "scale" : "2x" + "scale" : "2x", + "size" : "40x40" }, { "idiom" : "ipad", - "size" : "76x76", - "scale" : "1x" + "scale" : "1x", + "size" : "76x76" }, { "idiom" : "ipad", - "size" : "76x76", - "scale" : "2x" + "scale" : "2x", + "size" : "76x76" }, { "idiom" : "ipad", - "size" : "83.5x83.5", - "scale" : "2x" + "scale" : "2x", + "size" : "83.5x83.5" + }, + { + "idiom" : "ios-marketing", + "scale" : "1x", + "size" : "1024x1024" } ], "info" : { - "version" : 1, - "author" : "xcode" + "author" : "xcode", + "version" : 1 } -} \ No newline at end of file +} diff --git a/Demo/PhotoBrowserDemo/MenuViewController.swift b/Demo/PhotoBrowserDemo/MenuViewController.swift index b14abd26..02f03ae1 100644 --- a/Demo/PhotoBrowserDemo/MenuViewController.swift +++ b/Demo/PhotoBrowserDemo/MenuViewController.swift @@ -8,7 +8,10 @@ import UIKit -class MenuViewController: UITableViewController, IDMPhotoBrowserDelegate { } +class MenuViewController: UITableViewController, IDMPhotoBrowserDelegate { + + let maxZoomScale : CGFloat = 8; // zoom in scale on double tap can be define here now +} // MARK: View Lifecycle @@ -59,7 +62,7 @@ extension MenuViewController { // MARK: Actions extension MenuViewController { - func buttonWithImageOnScreenPressed(sender: AnyObject) { + @objc func buttonWithImageOnScreenPressed(sender: AnyObject) { let buttonSender = sender as? UIButton // Create an array to store IDMPhoto objects @@ -95,7 +98,7 @@ extension MenuViewController { photo.caption = "Grotto of the Madonna"; photos.append(photo) } - + // Create and setup browser let browser: IDMPhotoBrowser = IDMPhotoBrowser(photos: photos, animatedFrom: buttonSender) // using initWithPhotos:animatedFromView: browser.delegate = self @@ -105,7 +108,7 @@ extension MenuViewController { browser.usePopAnimation = true browser.scaleImage = buttonSender?.currentImage browser.dismissOnTouch = true - + browser.maximumDoubleTapZoomScale = CGFloat(maxZoomScale); // Show self.present(browser, animated: true, completion: nil) } @@ -244,7 +247,7 @@ extension MenuViewController { browser?.trackTintColor = UIColor.init(white: 0.8, alpha: 1) } } - + browser!.maximumDoubleTapZoomScale = CGFloat(maxZoomScale); // Show present(browser!, animated: true, completion: nil) diff --git a/Demo/PhotoBrowserDemo/PhotoBrowserDemo-Bridging-Header.h b/Demo/PhotoBrowserDemo/PhotoBrowserDemo-Bridging-Header.h index 6d4b5549..e80db944 100644 --- a/Demo/PhotoBrowserDemo/PhotoBrowserDemo-Bridging-Header.h +++ b/Demo/PhotoBrowserDemo/PhotoBrowserDemo-Bridging-Header.h @@ -2,5 +2,5 @@ // Use this file to import your target's public headers that you would like to expose to Swift. // -#import "Menu.h" +//#import "Menu.h" #import "IDMPhotoBrowser.h" diff --git a/Demo/Podfile.lock b/Demo/Podfile.lock index 08ad9620..a0073d7d 100644 --- a/Demo/Podfile.lock +++ b/Demo/Podfile.lock @@ -1,20 +1,26 @@ PODS: - DACircularProgress (2.3.1) - - pop (1.0.9) - - SDWebImage (4.0.0): - - SDWebImage/Core (= 4.0.0) - - SDWebImage/Core (4.0.0) + - pop (1.0.12) + - SDWebImage (5.9.5): + - SDWebImage/Core (= 5.9.5) + - SDWebImage/Core (5.9.5) DEPENDENCIES: - DACircularProgress - pop - SDWebImage +SPEC REPOS: + https://github.com/CocoaPods/Specs.git: + - DACircularProgress + - pop + - SDWebImage + SPEC CHECKSUMS: DACircularProgress: 4dd437c0fc3da5161cb289e07ac449493d41db71 - pop: f667631a5108a2e60d9e8797c9b32ddaf2080bce - SDWebImage: 76a6348bdc74eb5a55dd08a091ef298e56b55e41 + pop: d582054913807fd11fd50bfe6a539d91c7e1a55a + SDWebImage: 0b2ba0d56479bf6a45ecddbfd5558bea93150d25 PODFILE CHECKSUM: 7c9b8bb160246eb04b56feab0ec4a8fb149d5fa3 -COCOAPODS: 1.2.0 +COCOAPODS: 1.10.1 From 45c49f7f6664b7d69a6402eedffa2541edbadac9 Mon Sep 17 00:00:00 2001 From: jams032 Date: Thu, 29 Jul 2021 21:03:33 +0600 Subject: [PATCH 2/2] - Code Re-indent - Code Re-indent --- .../PhotoBrowserDemo/MenuViewController.swift | 460 +++++++++--------- 1 file changed, 230 insertions(+), 230 deletions(-) diff --git a/Demo/PhotoBrowserDemo/MenuViewController.swift b/Demo/PhotoBrowserDemo/MenuViewController.swift index 02f03ae1..6979c27f 100644 --- a/Demo/PhotoBrowserDemo/MenuViewController.swift +++ b/Demo/PhotoBrowserDemo/MenuViewController.swift @@ -16,267 +16,267 @@ class MenuViewController: UITableViewController, IDMPhotoBrowserDelegate { // MARK: View Lifecycle extension MenuViewController { - override func viewDidLoad() { - self.setupTableViewFooterView() - } + override func viewDidLoad() { + self.setupTableViewFooterView() + } } // MARK: Layout extension MenuViewController { - override var prefersStatusBarHidden: Bool { - return true - } + override var prefersStatusBarHidden: Bool { + return true + } } // MARK: General extension MenuViewController { - func setupTableViewFooterView() { - let tableViewFooter: UIView = UIView(frame: CGRect.init(x: 0, y: 0, width: 320, height: 426 * 0.9 + 40)) - - let buttonWithImageOnScreen1 = UIButton(type: .custom) - buttonWithImageOnScreen1.frame = CGRect.init(x: 15, y: 0, width: 640/3 * 0.9, height: 426/2 * 0.9) - buttonWithImageOnScreen1.tag = 101 - buttonWithImageOnScreen1.adjustsImageWhenHighlighted = false - buttonWithImageOnScreen1.setImage(UIImage.init(named: "photo1m.jpg"), for: .normal) - buttonWithImageOnScreen1.imageView?.contentMode = .scaleAspectFill - buttonWithImageOnScreen1.backgroundColor = UIColor.black - buttonWithImageOnScreen1.addTarget(self, action: #selector(buttonWithImageOnScreenPressed(sender:)), for: .touchUpInside) - tableViewFooter.addSubview(buttonWithImageOnScreen1) - - let buttonWithImageOnScreen2 = UIButton(type: .custom) - buttonWithImageOnScreen2.frame = CGRect.init(x: 15, y: 426/2 * 0.9 + 20, width: 640/3 * 0.9, height: 426/2 * 0.9) - buttonWithImageOnScreen2.tag = 102 - buttonWithImageOnScreen2.adjustsImageWhenHighlighted = false - buttonWithImageOnScreen2.setImage(UIImage.init(named: "photo3m.jpg"), for: .normal) - buttonWithImageOnScreen2.imageView?.contentMode = .scaleAspectFill - buttonWithImageOnScreen2.backgroundColor = UIColor.black - buttonWithImageOnScreen2.addTarget(self, action: #selector(buttonWithImageOnScreenPressed(sender:)), for: .touchUpInside) - tableViewFooter.addSubview(buttonWithImageOnScreen2) - - self.tableView.tableFooterView = tableViewFooter; - } + func setupTableViewFooterView() { + let tableViewFooter: UIView = UIView(frame: CGRect.init(x: 0, y: 0, width: 320, height: 426 * 0.9 + 40)) + + let buttonWithImageOnScreen1 = UIButton(type: .custom) + buttonWithImageOnScreen1.frame = CGRect.init(x: 15, y: 0, width: 640/3 * 0.9, height: 426/2 * 0.9) + buttonWithImageOnScreen1.tag = 101 + buttonWithImageOnScreen1.adjustsImageWhenHighlighted = false + buttonWithImageOnScreen1.setImage(UIImage.init(named: "photo1m.jpg"), for: .normal) + buttonWithImageOnScreen1.imageView?.contentMode = .scaleAspectFill + buttonWithImageOnScreen1.backgroundColor = UIColor.black + buttonWithImageOnScreen1.addTarget(self, action: #selector(buttonWithImageOnScreenPressed(sender:)), for: .touchUpInside) + tableViewFooter.addSubview(buttonWithImageOnScreen1) + + let buttonWithImageOnScreen2 = UIButton(type: .custom) + buttonWithImageOnScreen2.frame = CGRect.init(x: 15, y: 426/2 * 0.9 + 20, width: 640/3 * 0.9, height: 426/2 * 0.9) + buttonWithImageOnScreen2.tag = 102 + buttonWithImageOnScreen2.adjustsImageWhenHighlighted = false + buttonWithImageOnScreen2.setImage(UIImage.init(named: "photo3m.jpg"), for: .normal) + buttonWithImageOnScreen2.imageView?.contentMode = .scaleAspectFill + buttonWithImageOnScreen2.backgroundColor = UIColor.black + buttonWithImageOnScreen2.addTarget(self, action: #selector(buttonWithImageOnScreenPressed(sender:)), for: .touchUpInside) + tableViewFooter.addSubview(buttonWithImageOnScreen2) + + self.tableView.tableFooterView = tableViewFooter; + } } // MARK: Actions extension MenuViewController { @objc func buttonWithImageOnScreenPressed(sender: AnyObject) { - let buttonSender = sender as? UIButton - - // Create an array to store IDMPhoto objects - var photos: [IDMPhoto] = [] - - var photo: IDMPhoto - - if buttonSender?.tag == 101 { - let path_photo1l = [Bundle.main.path(forResource: "photo1l", ofType: "jpg")] - photo = IDMPhoto.photos(withFilePaths:path_photo1l).first as! IDMPhoto - photo.caption = "Grotto of the Madonna" - photos.append(photo) - } - - let path_photo3l = [Bundle.main.path(forResource: "photo3l", ofType: "jpg")] - photo = IDMPhoto.photos(withFilePaths:path_photo3l).first as! IDMPhoto - photo.caption = "York Floods" - photos.append(photo) - - let path_photo2l = [Bundle.main.path(forResource: "photo2l", ofType: "jpg")] - photo = IDMPhoto.photos(withFilePaths:path_photo2l).first as! IDMPhoto - photo.caption = "The London Eye is a giant Ferris wheel situated on the banks of the River Thames, in London, England." - photos.append(photo) - - let path_photo4l = [Bundle.main.path(forResource: "photo4l", ofType: "jpg")] - photo = IDMPhoto.photos(withFilePaths:path_photo4l).first as! IDMPhoto - photo.caption = "Campervan"; - photos.append(photo) - - if buttonSender?.tag == 102 { - let path_photo1l = [Bundle.main.path(forResource: "photo1l", ofType: "jpg")] - photo = IDMPhoto.photos(withFilePaths:path_photo1l).first as! IDMPhoto - photo.caption = "Grotto of the Madonna"; - photos.append(photo) - } - - // Create and setup browser - let browser: IDMPhotoBrowser = IDMPhotoBrowser(photos: photos, animatedFrom: buttonSender) // using initWithPhotos:animatedFromView: - browser.delegate = self - browser.displayActionButton = false - browser.displayArrowButton = true - browser.displayCounterLabel = true - browser.usePopAnimation = true - browser.scaleImage = buttonSender?.currentImage - browser.dismissOnTouch = true + let buttonSender = sender as? UIButton + + // Create an array to store IDMPhoto objects + var photos: [IDMPhoto] = [] + + var photo: IDMPhoto + + if buttonSender?.tag == 101 { + let path_photo1l = [Bundle.main.path(forResource: "photo1l", ofType: "jpg")] + photo = IDMPhoto.photos(withFilePaths:path_photo1l).first as! IDMPhoto + photo.caption = "Grotto of the Madonna" + photos.append(photo) + } + + let path_photo3l = [Bundle.main.path(forResource: "photo3l", ofType: "jpg")] + photo = IDMPhoto.photos(withFilePaths:path_photo3l).first as! IDMPhoto + photo.caption = "York Floods" + photos.append(photo) + + let path_photo2l = [Bundle.main.path(forResource: "photo2l", ofType: "jpg")] + photo = IDMPhoto.photos(withFilePaths:path_photo2l).first as! IDMPhoto + photo.caption = "The London Eye is a giant Ferris wheel situated on the banks of the River Thames, in London, England." + photos.append(photo) + + let path_photo4l = [Bundle.main.path(forResource: "photo4l", ofType: "jpg")] + photo = IDMPhoto.photos(withFilePaths:path_photo4l).first as! IDMPhoto + photo.caption = "Campervan"; + photos.append(photo) + + if buttonSender?.tag == 102 { + let path_photo1l = [Bundle.main.path(forResource: "photo1l", ofType: "jpg")] + photo = IDMPhoto.photos(withFilePaths:path_photo1l).first as! IDMPhoto + photo.caption = "Grotto of the Madonna"; + photos.append(photo) + } + + // Create and setup browser + let browser: IDMPhotoBrowser = IDMPhotoBrowser(photos: photos, animatedFrom: buttonSender) // using initWithPhotos:animatedFromView: + browser.delegate = self + browser.displayActionButton = false + browser.displayArrowButton = true + browser.displayCounterLabel = true + browser.usePopAnimation = true + browser.scaleImage = buttonSender?.currentImage + browser.dismissOnTouch = true browser.maximumDoubleTapZoomScale = CGFloat(maxZoomScale); - // Show - self.present(browser, animated: true, completion: nil) - } + // Show + self.present(browser, animated: true, completion: nil) + } } // MARK: TableView Data Source extension MenuViewController { - override func numberOfSections(in tableView: UITableView) -> Int { - return 3 - } - - override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - switch section { - case 0: - return 1 - case 1: - return 3 - case 2: - return 0 - default: - return 0 - } - } - - override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { - switch section { - case 0: - return "Single photo" - case 1: - return "Multiple photos" - case 2: - return "Photos on screen" - default: - return "" - } - } - - override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - // Create - let cellIdentifier = "Cell"; - var cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier) - if cell == nil { - cell = UITableViewCell.init(style: .default, reuseIdentifier: cellIdentifier) - } - - // Configure - if indexPath.section == 0 { - cell?.textLabel?.text = "Local photo" - } else if indexPath.section == 1 { - switch indexPath.row { - case 0: - cell?.textLabel?.text = "Local photos" - case 1: - cell?.textLabel?.text = "Photos from Flickr" - case 2: - cell?.textLabel?.text = "Photos from Flickr - Custom" - default: - break - } - } - - return cell! - } + override func numberOfSections(in tableView: UITableView) -> Int { + return 3 + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + switch section { + case 0: + return 1 + case 1: + return 3 + case 2: + return 0 + default: + return 0 + } + } + + override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { + switch section { + case 0: + return "Single photo" + case 1: + return "Multiple photos" + case 2: + return "Photos on screen" + default: + return "" + } + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + // Create + let cellIdentifier = "Cell"; + var cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier) + if cell == nil { + cell = UITableViewCell.init(style: .default, reuseIdentifier: cellIdentifier) + } + + // Configure + if indexPath.section == 0 { + cell?.textLabel?.text = "Local photo" + } else if indexPath.section == 1 { + switch indexPath.row { + case 0: + cell?.textLabel?.text = "Local photos" + case 1: + cell?.textLabel?.text = "Photos from Flickr" + case 2: + cell?.textLabel?.text = "Photos from Flickr - Custom" + default: + break + } + } + + return cell! + } } // MARK: TableView Delegate extension MenuViewController { - override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - tableView.deselectRow(at: indexPath, animated: true) - - // Create an array to store IDMPhoto objects - var photos: [IDMPhoto] = [] - - var photo: IDMPhoto - - if indexPath.section == 0 { // Local photo - let path_photo2l = [Bundle.main.path(forResource: "photo2l", ofType: "jpg")] - photo = IDMPhoto.photos(withFilePaths:path_photo2l).first as! IDMPhoto - photo.caption = "The London Eye is a giant Ferris wheel situated on the banks of the River Thames, in London, England." - photos.append(photo) - } - else if indexPath.section == 1 { // Multiple photos - if indexPath.row == 0 { // Local Photos - - let path_photo1l = [Bundle.main.path(forResource: "photo1l", ofType: "jpg")] - photo = IDMPhoto.photos(withFilePaths:path_photo1l).first as! IDMPhoto - photo.caption = "Grotto of the Madonna" - photos.append(photo) - - let path_photo2l = [Bundle.main.path(forResource: "photo2l", ofType: "jpg")] - photo = IDMPhoto.photos(withFilePaths:path_photo2l).first as! IDMPhoto - photo.caption = "The London Eye is a giant Ferris wheel situated on the banks of the River Thames, in London, England." - photos.append(photo) - - let path_photo3l = [Bundle.main.path(forResource: "photo3l", ofType: "jpg")] - photo = IDMPhoto.photos(withFilePaths:path_photo3l).first as! IDMPhoto - photo.caption = "York Floods" - photos.append(photo) - - let path_photo4l = [Bundle.main.path(forResource: "photo4l", ofType: "jpg")] - photo = IDMPhoto.photos(withFilePaths:path_photo4l).first as! IDMPhoto - photo.caption = "Campervan"; - photos.append(photo) - } else if indexPath.row == 1 || indexPath.row == 2 { // Photos from Flickr or Flickr - Custom - let photosWithURLArray = [NSURL.init(string: "http://farm4.static.flickr.com/3567/3523321514_371d9ac42f_b.jpg"), - NSURL.init(string: "http://farm4.static.flickr.com/3629/3339128908_7aecabc34b_b.jpg"), - NSURL.init(string: "http://farm4.static.flickr.com/3364/3338617424_7ff836d55f_b.jpg"), - NSURL.init(string: "http://farm4.static.flickr.com/3590/3329114220_5fbc5bc92b_b.jpg")] - let photosWithURL: [IDMPhoto] = IDMPhoto.photos(withURLs: photosWithURLArray) as! [IDMPhoto] - - photos = photosWithURL - } - } - - // Create and setup browser - let browser = IDMPhotoBrowser.init(photos: photos) - browser?.delegate = self - - if indexPath.section == 1 { // Multiple photos - if indexPath.row == 1 { // Photos from Flickr - browser?.displayCounterLabel = true - browser?.displayActionButton = false - } else if indexPath.row == 2 { // Photos from Flickr - Custom - browser?.actionButtonTitles = ["Option 1", "Option 2", "Option 3", "Option 4"] - browser?.displayCounterLabel = true - browser?.useWhiteBackgroundColor = true - browser?.leftArrowImage = UIImage.init(named: "IDMPhotoBrowser_customArrowLeft.png") - browser?.rightArrowImage = UIImage.init(named: "IDMPhotoBrowser_customArrowRight.png") - browser?.leftArrowSelectedImage = UIImage.init(named: "IDMPhotoBrowser_customArrowLeftSelected.png") - browser?.rightArrowSelectedImage = UIImage.init(named: "IDMPhotoBrowser_customArrowRightSelected.png") - browser?.doneButtonImage = UIImage.init(named: "IDMPhotoBrowser_customDoneButton.png") - browser?.view.tintColor = UIColor.orange - browser?.progressTintColor = UIColor.orange - browser?.trackTintColor = UIColor.init(white: 0.8, alpha: 1) - } - } + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + tableView.deselectRow(at: indexPath, animated: true) + + // Create an array to store IDMPhoto objects + var photos: [IDMPhoto] = [] + + var photo: IDMPhoto + + if indexPath.section == 0 { // Local photo + let path_photo2l = [Bundle.main.path(forResource: "photo2l", ofType: "jpg")] + photo = IDMPhoto.photos(withFilePaths:path_photo2l).first as! IDMPhoto + photo.caption = "The London Eye is a giant Ferris wheel situated on the banks of the River Thames, in London, England." + photos.append(photo) + } + else if indexPath.section == 1 { // Multiple photos + if indexPath.row == 0 { // Local Photos + + let path_photo1l = [Bundle.main.path(forResource: "photo1l", ofType: "jpg")] + photo = IDMPhoto.photos(withFilePaths:path_photo1l).first as! IDMPhoto + photo.caption = "Grotto of the Madonna" + photos.append(photo) + + let path_photo2l = [Bundle.main.path(forResource: "photo2l", ofType: "jpg")] + photo = IDMPhoto.photos(withFilePaths:path_photo2l).first as! IDMPhoto + photo.caption = "The London Eye is a giant Ferris wheel situated on the banks of the River Thames, in London, England." + photos.append(photo) + + let path_photo3l = [Bundle.main.path(forResource: "photo3l", ofType: "jpg")] + photo = IDMPhoto.photos(withFilePaths:path_photo3l).first as! IDMPhoto + photo.caption = "York Floods" + photos.append(photo) + + let path_photo4l = [Bundle.main.path(forResource: "photo4l", ofType: "jpg")] + photo = IDMPhoto.photos(withFilePaths:path_photo4l).first as! IDMPhoto + photo.caption = "Campervan"; + photos.append(photo) + } else if indexPath.row == 1 || indexPath.row == 2 { // Photos from Flickr or Flickr - Custom + let photosWithURLArray = [NSURL.init(string: "http://farm4.static.flickr.com/3567/3523321514_371d9ac42f_b.jpg"), + NSURL.init(string: "http://farm4.static.flickr.com/3629/3339128908_7aecabc34b_b.jpg"), + NSURL.init(string: "http://farm4.static.flickr.com/3364/3338617424_7ff836d55f_b.jpg"), + NSURL.init(string: "http://farm4.static.flickr.com/3590/3329114220_5fbc5bc92b_b.jpg")] + let photosWithURL: [IDMPhoto] = IDMPhoto.photos(withURLs: photosWithURLArray) as! [IDMPhoto] + + photos = photosWithURL + } + } + + // Create and setup browser + let browser = IDMPhotoBrowser.init(photos: photos) + browser?.delegate = self + + if indexPath.section == 1 { // Multiple photos + if indexPath.row == 1 { // Photos from Flickr + browser?.displayCounterLabel = true + browser?.displayActionButton = false + } else if indexPath.row == 2 { // Photos from Flickr - Custom + browser?.actionButtonTitles = ["Option 1", "Option 2", "Option 3", "Option 4"] + browser?.displayCounterLabel = true + browser?.useWhiteBackgroundColor = true + browser?.leftArrowImage = UIImage.init(named: "IDMPhotoBrowser_customArrowLeft.png") + browser?.rightArrowImage = UIImage.init(named: "IDMPhotoBrowser_customArrowRight.png") + browser?.leftArrowSelectedImage = UIImage.init(named: "IDMPhotoBrowser_customArrowLeftSelected.png") + browser?.rightArrowSelectedImage = UIImage.init(named: "IDMPhotoBrowser_customArrowRightSelected.png") + browser?.doneButtonImage = UIImage.init(named: "IDMPhotoBrowser_customDoneButton.png") + browser?.view.tintColor = UIColor.orange + browser?.progressTintColor = UIColor.orange + browser?.trackTintColor = UIColor.init(white: 0.8, alpha: 1) + } + } browser!.maximumDoubleTapZoomScale = CGFloat(maxZoomScale); - // Show - present(browser!, animated: true, completion: nil) - - tableView.deselectRow(at: indexPath, animated: true) - } + // Show + present(browser!, animated: true, completion: nil) + + tableView.deselectRow(at: indexPath, animated: true) + } } // MARK: IDMPhotoBrowser Delegate extension MenuViewController { - func photoBrowser(_ photoBrowser: IDMPhotoBrowser!, didShowPhotoAt index: UInt) { - let photo: IDMPhoto = photoBrowser.photo(at: index) as! IDMPhoto - print("Did show photoBrowser with photo index: \(index), photo caption: \(photo.caption)") - } - - func photoBrowser(_ photoBrowser: IDMPhotoBrowser!, willDismissAtPageIndex index: UInt) { - let photo: IDMPhoto = photoBrowser.photo(at: index) as! IDMPhoto - print("Will dismiss photoBrowser with photo index: \(index), photo caption: \(photo.caption)") - } - - func photoBrowser(_ photoBrowser: IDMPhotoBrowser!, didDismissAtPageIndex index: UInt) { - let photo: IDMPhoto = photoBrowser.photo(at: index) as! IDMPhoto - print("Did dismiss photoBrowser with photo index: \(index), photo caption: \(photo.caption)") - } - - func photoBrowser(_ photoBrowser: IDMPhotoBrowser!, didDismissActionSheetWithButtonIndex buttonIndex: UInt, photoIndex: UInt) { - let photo: IDMPhoto = photoBrowser.photo(at: buttonIndex) as! IDMPhoto - print("Did dismiss photoBrowser with photo index: \(buttonIndex), photo caption: \(photo.caption)") - - UIAlertView(title: "Option \(buttonIndex+1)", message: nil, delegate: nil, cancelButtonTitle: "OK").show() - } + func photoBrowser(_ photoBrowser: IDMPhotoBrowser!, didShowPhotoAt index: UInt) { + let photo: IDMPhoto = photoBrowser.photo(at: index) as! IDMPhoto + print("Did show photoBrowser with photo index: \(index), photo caption: \(photo.caption)") + } + + func photoBrowser(_ photoBrowser: IDMPhotoBrowser!, willDismissAtPageIndex index: UInt) { + let photo: IDMPhoto = photoBrowser.photo(at: index) as! IDMPhoto + print("Will dismiss photoBrowser with photo index: \(index), photo caption: \(photo.caption)") + } + + func photoBrowser(_ photoBrowser: IDMPhotoBrowser!, didDismissAtPageIndex index: UInt) { + let photo: IDMPhoto = photoBrowser.photo(at: index) as! IDMPhoto + print("Did dismiss photoBrowser with photo index: \(index), photo caption: \(photo.caption)") + } + + func photoBrowser(_ photoBrowser: IDMPhotoBrowser!, didDismissActionSheetWithButtonIndex buttonIndex: UInt, photoIndex: UInt) { + let photo: IDMPhoto = photoBrowser.photo(at: buttonIndex) as! IDMPhoto + print("Did dismiss photoBrowser with photo index: \(buttonIndex), photo caption: \(photo.caption)") + + UIAlertView(title: "Option \(buttonIndex+1)", message: nil, delegate: nil, cancelButtonTitle: "OK").show() + } }