From 4c8e04e902ef2a977ef0d45e720a7b23ee0d8343 Mon Sep 17 00:00:00 2001 From: Alexsander Khitev Date: Wed, 23 Mar 2016 17:39:19 +0400 Subject: [PATCH] update for new swift --- SKPhotoBrowser/SKPhotoBrowser.swift | 44 ++++++++++++++----- .../project.pbxproj | 12 +---- .../CameraRollViewController.swift | 2 +- 3 files changed, 36 insertions(+), 22 deletions(-) diff --git a/SKPhotoBrowser/SKPhotoBrowser.swift b/SKPhotoBrowser/SKPhotoBrowser.swift index cedeec1..08e07a2 100644 --- a/SKPhotoBrowser/SKPhotoBrowser.swift +++ b/SKPhotoBrowser/SKPhotoBrowser.swift @@ -237,7 +237,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { modalPresentationCapturesStatusBarAppearance = true modalTransitionStyle = UIModalTransitionStyle.CrossDissolve - NSNotificationCenter.defaultCenter().addObserver(self, selector: "handleSKPhotoLoadingDidEndNotification:", name: SKPHOTO_LOADING_DID_END_NOTIFICATION, object: nil) + NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(SKPhotoBrowser.handleSKPhotoLoadingDidEndNotification(_:)), name: SKPHOTO_LOADING_DID_END_NOTIFICATION, object: nil) } // MARK: - override @@ -282,7 +282,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { previousBtn.frame = CGRect(x: 0, y: 0, width: 44, height: 44) previousBtn.imageEdgeInsets = UIEdgeInsetsMake(13.25, 17.25, 13.25, 17.25) previousBtn.setImage(previousImage, forState: .Normal) - previousBtn.addTarget(self, action: "gotoPreviousPage", forControlEvents: .TouchUpInside) + previousBtn.addTarget(self, action: #selector(SKPhotoBrowser.gotoPreviousPage), forControlEvents: .TouchUpInside) previousBtn.contentMode = .Center toolPreviousButton = UIBarButtonItem(customView: previousBtn) @@ -292,7 +292,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { nextBtn.frame = CGRect(x: 0, y: 0, width: 44, height: 44) nextBtn.imageEdgeInsets = UIEdgeInsetsMake(13.25, 17.25, 13.25, 17.25) nextBtn.setImage(nextImage, forState: .Normal) - nextBtn.addTarget(self, action: "gotoNextPage", forControlEvents: .TouchUpInside) + nextBtn.addTarget(self, action: #selector(SKPhotoBrowser.gotoNextPage), forControlEvents: .TouchUpInside) nextBtn.contentMode = .Center toolNextButton = UIBarButtonItem(customView: nextBtn) @@ -314,11 +314,11 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { setSettingCustomDeleteButton() // action button - toolActionButton = UIBarButtonItem(barButtonSystemItem: .Action, target: self, action: "actionButtonPressed") + toolActionButton = UIBarButtonItem(barButtonSystemItem: .Action, target: self, action: #selector(SKPhotoBrowser.actionButtonPressed)) toolActionButton.tintColor = .whiteColor() // gesture - panGesture = UIPanGestureRecognizer(target: self, action: "panGestureRecognized:") + panGesture = UIPanGestureRecognizer(target: self, action: #selector(SKPhotoBrowser.panGestureRecognized(_:))) panGesture.minimumNumberOfTouches = 1 panGesture.maximumNumberOfTouches = 1 @@ -413,7 +413,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { closeButton.imageEdgeInsets = UIEdgeInsetsMake(12, 12, 12, 12) } closeButton.backgroundColor = .clearColor() - closeButton.addTarget(self, action: "closeButtonPressed:", forControlEvents: UIControlEvents.TouchUpInside) + closeButton.addTarget(self, action: #selector(SKPhotoBrowser.closeButtonPressed(_:)), forControlEvents: UIControlEvents.TouchUpInside) closeButtonHideFrame = CGRect(x: 5, y: -20, width: 44, height: 44) closeButtonShowFrame = CGRect(x: 5, y: buttonTopOffset, width: 44, height: 44) view.addSubview(closeButton) @@ -436,7 +436,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { deleteButton.imageEdgeInsets = UIEdgeInsetsMake(12.3, 12.3, 12.3, 12.3) } deleteButton.setImage(image, forState: .Normal) - deleteButton.addTarget(self, action: "deleteButtonPressed:", forControlEvents: UIControlEvents.TouchUpInside) + deleteButton.addTarget(self, action: #selector(SKPhotoBrowser.deleteButtonPressed(_:)), forControlEvents: UIControlEvents.TouchUpInside) deleteButton.alpha = 0.0 view.addSubview(deleteButton) deleteButton.translatesAutoresizingMaskIntoConstraints = true @@ -451,7 +451,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { if displayCustomCloseButton == true { let closeImage = UIImage(named: "SKPhotoBrowser.bundle/images/btn_common_close_wh", inBundle: bundle, compatibleWithTraitCollection: nil) ?? UIImage() customCloseButton = UIButton(type: .Custom) - customCloseButton.addTarget(self, action: "closeButtonPressed:", forControlEvents: .TouchUpInside) + customCloseButton.addTarget(self, action: #selector(SKPhotoBrowser.closeButtonPressed(_:)), forControlEvents: .TouchUpInside) customCloseButton.backgroundColor = .clearColor() // If another developer has not set their values if customCloseButtonImage != nil { @@ -479,7 +479,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { if displayCustomDeleteButton == true { customDeleteButton = UIButton(type: .Custom) customDeleteButton.backgroundColor = .clearColor() - customDeleteButton.addTarget(self, action: "deleteButtonPressed:", forControlEvents: .TouchUpInside) + customDeleteButton.addTarget(self, action: #selector(SKPhotoBrowser.deleteButtonPressed(_:)), forControlEvents: .TouchUpInside) // If another developer has not set their values if customDeleteButtonShowFrame == nil && customDeleteButtonHideFrame == nil { customDeleteButtonShowFrame = CGRect(x: view.frame.width - 44, y: buttonTopOffset, width: 44, height: 44) @@ -1030,7 +1030,29 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { recycledPages.removeFirst() } - for var index = firstIndex; index <= lastIndex; index++ { + // this is a new style but it works very slow +// for index in 0...lastIndex { +// if isDisplayingPageForIndex(index) { +// continue +// } +// +// let page = SKZoomingScrollView(frame: view.frame, browser: self) +// page.frame = frameForPageAtIndex(index) +// page.tag = index + pageIndexTagOffset +// page.photo = photoAtIndex(index) +// +// visiblePages.append(page) +// pagingScrollView.addSubview(page) +// // if exists caption, insert +// if let captionView = captionViewForPhotoAtIndex(index) { +// captionView.frame = frameForCaptionView(captionView, index: index) +// pagingScrollView.addSubview(captionView) +// // ref val for control +// page.captionView = captionView +// } +// } + + for var index = firstIndex; index <= lastIndex; index += 1 { if isDisplayingPageForIndex(index) { continue } @@ -1109,7 +1131,7 @@ public class SKPhotoBrowser: UIViewController, UIScrollViewDelegate { // reset cancelControlHiding() // start - controlVisibilityTimer = NSTimer.scheduledTimerWithTimeInterval(4.0, target: self, selector: "hideControls:", userInfo: nil, repeats: false) + controlVisibilityTimer = NSTimer.scheduledTimerWithTimeInterval(4.0, target: self, selector: #selector(SKPhotoBrowser.hideControls(_:)), userInfo: nil, repeats: false) } diff --git a/SKPhotoBrowserExample/SKPhotoBrowserExample.xcodeproj/project.pbxproj b/SKPhotoBrowserExample/SKPhotoBrowserExample.xcodeproj/project.pbxproj index 104f805..a16e34a 100644 --- a/SKPhotoBrowserExample/SKPhotoBrowserExample.xcodeproj/project.pbxproj +++ b/SKPhotoBrowserExample/SKPhotoBrowserExample.xcodeproj/project.pbxproj @@ -7,8 +7,6 @@ objects = { /* Begin PBXBuildFile section */ - 212705831C92BB2A00466223 /* SKPhotoBrowser.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8909B5711BC792570060A053 /* SKPhotoBrowser.framework */; }; - 212705841C92BB2A00466223 /* SKPhotoBrowser.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 8909B5711BC792570060A053 /* SKPhotoBrowser.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 212705891C92C69C00466223 /* CameraRollViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 212705881C92C69C00466223 /* CameraRollViewController.swift */; }; 8909B55B1BC792150060A053 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8909B55A1BC792150060A053 /* AppDelegate.swift */; }; 8909B55D1BC792150060A053 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8909B55C1BC792150060A053 /* ViewController.swift */; }; @@ -32,13 +30,6 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ - 212705851C92BB2A00466223 /* PBXContainerItemProxy */ = { - isa = PBXContainerItemProxy; - containerPortal = 8909B56C1BC792570060A053 /* SKPhotoBrowser.xcodeproj */; - proxyType = 1; - remoteGlobalIDString = 8909B52F1BC791280060A053; - remoteInfo = SKPhotoBrowser; - }; 8909B5701BC792570060A053 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 8909B56C1BC792570060A053 /* SKPhotoBrowser.xcodeproj */; @@ -197,7 +188,6 @@ TargetAttributes = { 8909B5561BC792150060A053 = { CreatedOnToolsVersion = 7.0; - DevelopmentTeam = M7NG7AS4GP; }; }; }; @@ -388,6 +378,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "iPhone Developer"; EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; INFOPLIST_FILE = SKPhotoBrowserExample/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -400,6 +391,7 @@ isa = XCBuildConfiguration; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_IDENTITY = "iPhone Developer"; EMBEDDED_CONTENT_CONTAINS_SWIFT = YES; INFOPLIST_FILE = SKPhotoBrowserExample/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; diff --git a/SKPhotoBrowserExample/SKPhotoBrowserExample/CameraRollViewController.swift b/SKPhotoBrowserExample/SKPhotoBrowserExample/CameraRollViewController.swift index 5ffbb0f..4352b05 100644 --- a/SKPhotoBrowserExample/SKPhotoBrowserExample/CameraRollViewController.swift +++ b/SKPhotoBrowserExample/SKPhotoBrowserExample/CameraRollViewController.swift @@ -124,7 +124,7 @@ class CameraRollViewController: UIViewController, SKPhotoBrowserDelegate, UIColl if let image = image, index = self?.assets.indexOf(asset) { fetchedImages[index] = image } - fetched++ + fetched += 1 if self?.assets.count == fetched { open(fetchedImages)