From 746e32052694a9e8efcb40268d84c33fec88239e Mon Sep 17 00:00:00 2001 From: f2m2rd Date: Tue, 16 Feb 2016 11:16:12 -0800 Subject: [PATCH 1/6] Update ALSpotlightView.podspec --- ALSpotlightView.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ALSpotlightView.podspec b/ALSpotlightView.podspec index 8b9cad3..333f936 100644 --- a/ALSpotlightView.podspec +++ b/ALSpotlightView.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| s.homepage = "http://github.com/al7/ALSpotlightView" s.license = "MIT" s.author = { "Alex Leite" => "admin@al7dev.com" } - s.platform = :ios, "8.0" + s.platform = :ios, "7.0" s.source = { :git => "https://github.com/al7/ALSpotlightView.git", :tag => "0.0.3" } s.source_files = "ALSpotlightView/Source", "ALSpotlightView/Source/**/*.{h,m,swift}" s.requires_arc = true From 79c16aa54633404c47f69cbe9124cb108da29e06 Mon Sep 17 00:00:00 2001 From: f2m2rd Date: Tue, 16 Feb 2016 11:17:05 -0800 Subject: [PATCH 2/6] Update ALSpotlightView.podspec --- ALSpotlightView.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ALSpotlightView.podspec b/ALSpotlightView.podspec index 333f936..8b9cad3 100644 --- a/ALSpotlightView.podspec +++ b/ALSpotlightView.podspec @@ -7,7 +7,7 @@ Pod::Spec.new do |s| s.homepage = "http://github.com/al7/ALSpotlightView" s.license = "MIT" s.author = { "Alex Leite" => "admin@al7dev.com" } - s.platform = :ios, "7.0" + s.platform = :ios, "8.0" s.source = { :git => "https://github.com/al7/ALSpotlightView.git", :tag => "0.0.3" } s.source_files = "ALSpotlightView/Source", "ALSpotlightView/Source/**/*.{h,m,swift}" s.requires_arc = true From fc6624ca0889d4af97122700e3af4281bb946e59 Mon Sep 17 00:00:00 2001 From: f2m2rd Date: Mon, 26 Sep 2016 11:32:23 -0700 Subject: [PATCH 3/6] Updated for Swift 2.3 --- ALSpotlightView/Source/ALSpotlightView.swift | 269 ++++++++++--------- 1 file changed, 135 insertions(+), 134 deletions(-) diff --git a/ALSpotlightView/Source/ALSpotlightView.swift b/ALSpotlightView/Source/ALSpotlightView.swift index 78a38e6..ef1da6e 100644 --- a/ALSpotlightView/Source/ALSpotlightView.swift +++ b/ALSpotlightView/Source/ALSpotlightView.swift @@ -1,17 +1,13 @@ /* - Copyright (c) 2015 - Alex Leite (al7dev) - Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -19,7 +15,6 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ import UIKit @@ -27,132 +22,138 @@ import UIKit public typealias SpotlightTapHandler = () -> Void public class ALSpotlightView: UIView { - - public var spotlightCenter: CGPoint = CGPoint(x: 0.5, y: 0.5) - public var spotlightRadius: CGFloat = 200.0 - public var modalOpacity: CGFloat = 0.6 - private weak var _targetView: UIView? - public var targetView: UIView? { get { return _targetView } } - public var onTapHandler: SpotlightTapHandler? - - public init(spotlightCenter: CGPoint, spotlightRadius: CGFloat = 200.0, modalOpacity: CGFloat = 0.6, onTapHandler: SpotlightTapHandler? = nil) { - super.init(frame: CGRectZero) - self.backgroundColor = UIColor.clearColor() - self.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] - self.spotlightRadius = spotlightRadius - self.spotlightCenter = spotlightCenter - self.modalOpacity = modalOpacity - self.onTapHandler = onTapHandler - } - - override public init(frame: CGRect) { - fatalError("init(frame:) not available. Please use designated initializer") - } - - required public init(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - //MARK- Base Overrides - - public override func drawRect(rect: CGRect) { - let context = UIGraphicsGetCurrentContext() - let colorSpace = CGColorSpaceCreateDeviceRGB() - let locations: [CGFloat] = [0.0, 1.0] - let colors: [CGFloat] = [ - 0.0, 0.0, 0.0, 0.0, - 0.0, 0.0, 0.0, self.modalOpacity - ] - let gradient = CGGradientCreateWithColorComponents(colorSpace, colors, locations, 2) - - let gradientCenter = CGPoint(x: self.spotlightCenter.x * rect.size.width, y: self.spotlightCenter.y * rect.size.height) - let startPoint = gradientCenter - let startRadius: CGFloat = 0.0 - let endPoint = gradientCenter - let endRadius = self.spotlightRadius - - CGContextDrawRadialGradient(context, gradient, startPoint, startRadius, endPoint, endRadius, .DrawsAfterEndLocation) - } - - public override func layoutSubviews() { - self.setNeedsDisplay() - } - - //MARK- Public Methods - - public func showInView(view: UIView?, animated: Bool = true, duration: NSTimeInterval = 0.3) { - self._targetView = (view != nil) ? view : UIApplication.sharedApplication().keyWindow - if let tv = self.targetView { - self.alpha = 0.0 - self.frame = tv.bounds - self.setNeedsDisplay() - tv.addSubview(self) - - let animation: () -> Void = { - self.alpha = 1.0 - } - - let completion: (Bool) -> Void = { - finished in - - let tapRecognizer = UITapGestureRecognizer(target: self, action: "onSpotlightViewTap:") - tapRecognizer.numberOfTapsRequired = 1 - self.addGestureRecognizer(tapRecognizer) - } - - if animated { - UIView.animateWithDuration(duration, animations: animation, completion: completion) - } - else { - animation() - } - } - } - - public func show(animated: Bool = true) { - self.showInView(nil, animated: animated) - } - - public func hide(animated: Bool = true, duration: NSTimeInterval = 0.3) { - self.clearGestureRecognizers() - self.onTapHandler = nil - - let animation: () -> Void = { - self.alpha = 0.0 - } - - let completion: (Bool) -> Void = { - finished in - - self._targetView = nil - self.removeFromSuperview() - } - - if animated { - UIView.animateWithDuration(duration, animations: animation, completion: completion) - } - else { - animation() - completion(true) - } - } - - //MARK- Helper Methods - - private func clearGestureRecognizers() { - if let recognizers = self.gestureRecognizers { - for recognizer in recognizers { - self.removeGestureRecognizer(recognizer) - } - } - } - - //MARK- Action Targets - - func onSpotlightViewTap(sender: UITapGestureRecognizer) { - if let handler = self.onTapHandler { - handler() - } - } - -} \ No newline at end of file + + public var spotlightCenter: CGPoint = CGPoint(x: 0.5, y: 0.5) + public var spotlightRadius: CGFloat = 200.0 + public var modalOpacity: CGFloat = 0.6 + private weak var _targetView: UIView? + public var targetView: UIView? { get { return _targetView } } + public var onTapHandler: SpotlightTapHandler? + + public init(spotlightCenter: CGPoint, spotlightRadius: CGFloat = 200.0, modalOpacity: CGFloat = 0.6, onTapHandler: SpotlightTapHandler? = nil) { + super.init(frame: CGRectZero) + self.backgroundColor = UIColor.clearColor() + self.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] + self.spotlightRadius = spotlightRadius + self.spotlightCenter = spotlightCenter + self.modalOpacity = modalOpacity + self.onTapHandler = onTapHandler + } + + override public init(frame: CGRect) { + fatalError("init(frame:) not available. Please use designated initializer") + } + + required public init(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + //MARK- Base Overrides + + public override func drawRect(rect: CGRect) { + + guard let context = UIGraphicsGetCurrentContext() else { + return + } + + let colorSpace = CGColorSpaceCreateDeviceRGB() + let locations: [CGFloat] = [0.0, 1.0] + let colors: [CGFloat] = [ + 0.0, 0.0, 0.0, 0.0, + 0.0, 0.0, 0.0, self.modalOpacity + ] + + guard let gradient = CGGradientCreateWithColorComponents(colorSpace, colors, locations, 2) else { + return + } + + let gradientCenter = CGPoint(x: self.spotlightCenter.x * rect.size.width, y: self.spotlightCenter.y * rect.size.height) + let startPoint = gradientCenter + let startRadius: CGFloat = 0.0 + let endPoint = gradientCenter + let endRadius = self.spotlightRadius + + CGContextDrawRadialGradient(context, gradient, startPoint, startRadius, endPoint, endRadius, .DrawsAfterEndLocation) + } + + public override func layoutSubviews() { + self.setNeedsDisplay() + } + + //MARK- Public Methods + + public func showInView(view: UIView?, animated: Bool = true, duration: NSTimeInterval = 0.3) { + self._targetView = (view != nil) ? view : UIApplication.sharedApplication().keyWindow + if let tv = self.targetView { + self.alpha = 0.0 + self.frame = tv.bounds + self.setNeedsDisplay() + tv.addSubview(self) + + let animation: () -> Void = { + self.alpha = 1.0 + } + + let completion: (Bool) -> Void = { + finished in + + let tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(ALSpotlightView.onSpotlightViewTap(_:))) + tapRecognizer.numberOfTapsRequired = 1 + self.addGestureRecognizer(tapRecognizer) + } + + if animated { + UIView.animateWithDuration(duration, animations: animation, completion: completion) + } + else { + animation() + } + } + } + + public func show(animated: Bool = true) { + self.showInView(nil, animated: animated) + } + + public func hide(animated: Bool = true, duration: NSTimeInterval = 0.3) { + self.clearGestureRecognizers() + self.onTapHandler = nil + + let animation: () -> Void = { + self.alpha = 0.0 + } + + let completion: (Bool) -> Void = { + finished in + + self._targetView = nil + self.removeFromSuperview() + } + + if animated { + UIView.animateWithDuration(duration, animations: animation, completion: completion) + } + else { + animation() + completion(true) + } + } + + //MARK- Helper Methods + + private func clearGestureRecognizers() { + if let recognizers = self.gestureRecognizers { + for recognizer in recognizers { + self.removeGestureRecognizer(recognizer) + } + } + } + + //MARK- Action Targets + + func onSpotlightViewTap(sender: UITapGestureRecognizer) { + if let handler = self.onTapHandler { + handler() + } + } +} From bc77bce411c1a7390af219f16804653324f1554f Mon Sep 17 00:00:00 2001 From: f2m2rd Date: Thu, 6 Oct 2016 10:50:33 -0700 Subject: [PATCH 4/6] Update ALSpotlightView.podspec --- ALSpotlightView.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ALSpotlightView.podspec b/ALSpotlightView.podspec index 8b9cad3..acfdb15 100644 --- a/ALSpotlightView.podspec +++ b/ALSpotlightView.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = "ALSpotlightView" - s.version = "0.0.2" + s.version = "0.0.3" s.summary = "Custom control that simulates a modal spotlight effect." s.homepage = "http://github.com/al7/ALSpotlightView" From 6475f79a8ad54fd4bbf6d4fcd54dc24a01b2806b Mon Sep 17 00:00:00 2001 From: Rocky Demoff Date: Sun, 12 Feb 2017 10:06:02 -0800 Subject: [PATCH 5/6] Swift 3 Upgrade --- ALSpotlightView.podspec | 4 +- ALSpotlightView.xcodeproj/project.pbxproj | 22 +++++++++- ALSpotlightView/AppDelegate.swift | 16 +++---- ALSpotlightView/Info.plist | 2 +- ALSpotlightView/Source/ALSpotlightView.swift | 44 +++++++++---------- ALSpotlightView/ViewController.swift | 18 ++++---- .../ALSpotlightViewTests.swift | 2 +- ALSpotlightViewTests/Info.plist | 2 +- 8 files changed, 65 insertions(+), 45 deletions(-) diff --git a/ALSpotlightView.podspec b/ALSpotlightView.podspec index acfdb15..698f659 100644 --- a/ALSpotlightView.podspec +++ b/ALSpotlightView.podspec @@ -1,14 +1,14 @@ Pod::Spec.new do |s| s.name = "ALSpotlightView" - s.version = "0.0.3" + s.version = "0.0.4" s.summary = "Custom control that simulates a modal spotlight effect." s.homepage = "http://github.com/al7/ALSpotlightView" s.license = "MIT" s.author = { "Alex Leite" => "admin@al7dev.com" } s.platform = :ios, "8.0" - s.source = { :git => "https://github.com/al7/ALSpotlightView.git", :tag => "0.0.3" } + s.source = { :git => "https://github.com/al7/ALSpotlightView.git", :tag => "0.0.4" } s.source_files = "ALSpotlightView/Source", "ALSpotlightView/Source/**/*.{h,m,swift}" s.requires_arc = true diff --git a/ALSpotlightView.xcodeproj/project.pbxproj b/ALSpotlightView.xcodeproj/project.pbxproj index ad7b8a8..41600e9 100644 --- a/ALSpotlightView.xcodeproj/project.pbxproj +++ b/ALSpotlightView.xcodeproj/project.pbxproj @@ -161,14 +161,16 @@ 137ACA4C1A9EEFC8006689AC /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0610; + LastUpgradeCheck = 0820; ORGANIZATIONNAME = "Alexandre Leite"; TargetAttributes = { 137ACA531A9EEFC8006689AC = { CreatedOnToolsVersion = 6.1.1; + LastSwiftMigration = 0820; }; 137ACA681A9EEFC8006689AC = { CreatedOnToolsVersion = 6.1.1; + LastSwiftMigration = 0820; TestTargetID = 137ACA531A9EEFC8006689AC; }; }; @@ -253,15 +255,19 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -296,8 +302,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -305,6 +313,7 @@ ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; @@ -314,6 +323,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 8.1; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -326,7 +336,9 @@ ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; INFOPLIST_FILE = ALSpotlightView/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.al7dev.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -337,7 +349,9 @@ ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; INFOPLIST_FILE = ALSpotlightView/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.al7dev.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -355,7 +369,9 @@ ); INFOPLIST_FILE = ALSpotlightViewTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.al7dev.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ALSpotlightView.app/ALSpotlightView"; }; name = Debug; @@ -370,7 +386,9 @@ ); INFOPLIST_FILE = ALSpotlightViewTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "com.al7dev.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ALSpotlightView.app/ALSpotlightView"; }; name = Release; @@ -394,6 +412,7 @@ 137ACA751A9EEFC8006689AC /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 137ACA761A9EEFC8006689AC /* Build configuration list for PBXNativeTarget "ALSpotlightViewTests" */ = { isa = XCConfigurationList; @@ -402,6 +421,7 @@ 137ACA781A9EEFC8006689AC /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/ALSpotlightView/AppDelegate.swift b/ALSpotlightView/AppDelegate.swift index 7a3bf12..b539810 100644 --- a/ALSpotlightView/AppDelegate.swift +++ b/ALSpotlightView/AppDelegate.swift @@ -12,32 +12,32 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { - self.window = UIWindow(frame: UIScreen.mainScreen().bounds) - self.window?.backgroundColor = UIColor.whiteColor() + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + self.window = UIWindow(frame: UIScreen.main.bounds) + self.window?.backgroundColor = UIColor.white self.window?.rootViewController = ViewController() self.window?.makeKeyAndVisible() return true } - func applicationWillResignActive(application: UIApplication) { + func applicationWillResignActive(_ application: UIApplication) { } - func applicationDidEnterBackground(application: UIApplication) { + func applicationDidEnterBackground(_ application: UIApplication) { } - func applicationWillEnterForeground(application: UIApplication) { + func applicationWillEnterForeground(_ application: UIApplication) { } - func applicationDidBecomeActive(application: UIApplication) { + func applicationDidBecomeActive(_ application: UIApplication) { } - func applicationWillTerminate(application: UIApplication) { + func applicationWillTerminate(_ application: UIApplication) { } diff --git a/ALSpotlightView/Info.plist b/ALSpotlightView/Info.plist index 6dcf8e9..2e9d12e 100644 --- a/ALSpotlightView/Info.plist +++ b/ALSpotlightView/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - com.al7dev.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/ALSpotlightView/Source/ALSpotlightView.swift b/ALSpotlightView/Source/ALSpotlightView.swift index ef1da6e..ca57ae1 100644 --- a/ALSpotlightView/Source/ALSpotlightView.swift +++ b/ALSpotlightView/Source/ALSpotlightView.swift @@ -21,19 +21,19 @@ import UIKit public typealias SpotlightTapHandler = () -> Void -public class ALSpotlightView: UIView { +open class ALSpotlightView: UIView { - public var spotlightCenter: CGPoint = CGPoint(x: 0.5, y: 0.5) - public var spotlightRadius: CGFloat = 200.0 - public var modalOpacity: CGFloat = 0.6 - private weak var _targetView: UIView? - public var targetView: UIView? { get { return _targetView } } - public var onTapHandler: SpotlightTapHandler? + open var spotlightCenter: CGPoint = CGPoint(x: 0.5, y: 0.5) + open var spotlightRadius: CGFloat = 200.0 + open var modalOpacity: CGFloat = 0.6 + fileprivate weak var _targetView: UIView? + open var targetView: UIView? { get { return _targetView } } + open var onTapHandler: SpotlightTapHandler? public init(spotlightCenter: CGPoint, spotlightRadius: CGFloat = 200.0, modalOpacity: CGFloat = 0.6, onTapHandler: SpotlightTapHandler? = nil) { - super.init(frame: CGRectZero) - self.backgroundColor = UIColor.clearColor() - self.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] + super.init(frame: CGRect.zero) + self.backgroundColor = UIColor.clear + self.autoresizingMask = [.flexibleWidth, .flexibleHeight] self.spotlightRadius = spotlightRadius self.spotlightCenter = spotlightCenter self.modalOpacity = modalOpacity @@ -50,7 +50,7 @@ public class ALSpotlightView: UIView { //MARK- Base Overrides - public override func drawRect(rect: CGRect) { + open override func draw(_ rect: CGRect) { guard let context = UIGraphicsGetCurrentContext() else { return @@ -63,7 +63,7 @@ public class ALSpotlightView: UIView { 0.0, 0.0, 0.0, self.modalOpacity ] - guard let gradient = CGGradientCreateWithColorComponents(colorSpace, colors, locations, 2) else { + guard let gradient = CGGradient(colorSpace: colorSpace, colorComponents: colors, locations: locations, count: 2) else { return } @@ -73,17 +73,17 @@ public class ALSpotlightView: UIView { let endPoint = gradientCenter let endRadius = self.spotlightRadius - CGContextDrawRadialGradient(context, gradient, startPoint, startRadius, endPoint, endRadius, .DrawsAfterEndLocation) + context.drawRadialGradient(gradient, startCenter: startPoint, startRadius: startRadius, endCenter: endPoint, endRadius: endRadius, options: .drawsAfterEndLocation) } - public override func layoutSubviews() { + open override func layoutSubviews() { self.setNeedsDisplay() } //MARK- Public Methods - public func showInView(view: UIView?, animated: Bool = true, duration: NSTimeInterval = 0.3) { - self._targetView = (view != nil) ? view : UIApplication.sharedApplication().keyWindow + open func showInView(_ view: UIView?, animated: Bool = true, duration: TimeInterval = 0.3) { + self._targetView = (view != nil) ? view : UIApplication.shared.keyWindow if let tv = self.targetView { self.alpha = 0.0 self.frame = tv.bounds @@ -103,7 +103,7 @@ public class ALSpotlightView: UIView { } if animated { - UIView.animateWithDuration(duration, animations: animation, completion: completion) + UIView.animate(withDuration: duration, animations: animation, completion: completion) } else { animation() @@ -111,11 +111,11 @@ public class ALSpotlightView: UIView { } } - public func show(animated: Bool = true) { + open func show(_ animated: Bool = true) { self.showInView(nil, animated: animated) } - public func hide(animated: Bool = true, duration: NSTimeInterval = 0.3) { + open func hide(_ animated: Bool = true, duration: TimeInterval = 0.3) { self.clearGestureRecognizers() self.onTapHandler = nil @@ -131,7 +131,7 @@ public class ALSpotlightView: UIView { } if animated { - UIView.animateWithDuration(duration, animations: animation, completion: completion) + UIView.animate(withDuration: duration, animations: animation, completion: completion) } else { animation() @@ -141,7 +141,7 @@ public class ALSpotlightView: UIView { //MARK- Helper Methods - private func clearGestureRecognizers() { + fileprivate func clearGestureRecognizers() { if let recognizers = self.gestureRecognizers { for recognizer in recognizers { self.removeGestureRecognizer(recognizer) @@ -151,7 +151,7 @@ public class ALSpotlightView: UIView { //MARK- Action Targets - func onSpotlightViewTap(sender: UITapGestureRecognizer) { + func onSpotlightViewTap(_ sender: UITapGestureRecognizer) { if let handler = self.onTapHandler { handler() } diff --git a/ALSpotlightView/ViewController.swift b/ALSpotlightView/ViewController.swift index a021c3d..8c1b67f 100644 --- a/ALSpotlightView/ViewController.swift +++ b/ALSpotlightView/ViewController.swift @@ -11,14 +11,14 @@ class ViewController: UIViewController { //MARK- View lifecycle override func loadView() { - self.view = UIView(frame: UIScreen.mainScreen().bounds) - self.view.backgroundColor = UIColor.whiteColor() + self.view = UIView(frame: UIScreen.main.bounds) + self.view.backgroundColor = UIColor.white let label = UILabel(frame: self.view.bounds) - label.textAlignment = .Center - label.autoresizingMask = .FlexibleWidth | .FlexibleHeight + label.textAlignment = .center + label.autoresizingMask = [.flexibleWidth, .flexibleHeight] label.numberOfLines = 0 - label.lineBreakMode = .ByWordWrapping + label.lineBreakMode = .byWordWrapping label.text = "Tap Anywhere in screen\nto see Spotlight View" self.view.addSubview(label) } @@ -26,16 +26,16 @@ class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: "onTap:") + let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(ViewController.onTap(_:))) tapGestureRecognizer.numberOfTapsRequired = 1 self.view.addGestureRecognizer(tapGestureRecognizer) } //MARK- Tap Gesture Recognizer - func onTap(sender: UITapGestureRecognizer) { - let location = sender.locationInView(self.view) - var spotlightCenter = CGPointZero + func onTap(_ sender: UITapGestureRecognizer) { + let location = sender.location(in: self.view) + var spotlightCenter = CGPoint.zero spotlightCenter.x = location.x / self.view.bounds.size.width spotlightCenter.y = location.y / self.view.bounds.size.height diff --git a/ALSpotlightViewTests/ALSpotlightViewTests.swift b/ALSpotlightViewTests/ALSpotlightViewTests.swift index 63c7775..62582d5 100644 --- a/ALSpotlightViewTests/ALSpotlightViewTests.swift +++ b/ALSpotlightViewTests/ALSpotlightViewTests.swift @@ -28,7 +28,7 @@ class ALSpotlightViewTests: XCTestCase { func testPerformanceExample() { // This is an example of a performance test case. - self.measureBlock() { + self.measure() { // Put the code you want to measure the time of here. } } diff --git a/ALSpotlightViewTests/Info.plist b/ALSpotlightViewTests/Info.plist index 87ccc92..ba72822 100644 --- a/ALSpotlightViewTests/Info.plist +++ b/ALSpotlightViewTests/Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable $(EXECUTABLE_NAME) CFBundleIdentifier - com.al7dev.$(PRODUCT_NAME:rfc1034identifier) + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName From 26f078d74c6820b8fea8785682c833d98a2532fc Mon Sep 17 00:00:00 2001 From: Rocky Demoff Date: Tue, 21 Nov 2017 14:24:47 -0800 Subject: [PATCH 6/6] Updated for Swift 4 --- ALSpotlightView.podspec | 6 ++--- ALSpotlightView.xcodeproj/project.pbxproj | 28 +++++++++++++++----- ALSpotlightView/Source/ALSpotlightView.swift | 2 +- ALSpotlightView/ViewController.swift | 2 +- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/ALSpotlightView.podspec b/ALSpotlightView.podspec index 698f659..0bb2643 100644 --- a/ALSpotlightView.podspec +++ b/ALSpotlightView.podspec @@ -1,14 +1,14 @@ Pod::Spec.new do |s| s.name = "ALSpotlightView" - s.version = "0.0.4" + s.version = "0.0.5" s.summary = "Custom control that simulates a modal spotlight effect." s.homepage = "http://github.com/al7/ALSpotlightView" s.license = "MIT" s.author = { "Alex Leite" => "admin@al7dev.com" } - s.platform = :ios, "8.0" - s.source = { :git => "https://github.com/al7/ALSpotlightView.git", :tag => "0.0.4" } + s.platform = :ios, "9.0" + s.source = { :git => "https://github.com/al7/ALSpotlightView.git", :tag => "0.0.5" } s.source_files = "ALSpotlightView/Source", "ALSpotlightView/Source/**/*.{h,m,swift}" s.requires_arc = true diff --git a/ALSpotlightView.xcodeproj/project.pbxproj b/ALSpotlightView.xcodeproj/project.pbxproj index 41600e9..8496fe7 100644 --- a/ALSpotlightView.xcodeproj/project.pbxproj +++ b/ALSpotlightView.xcodeproj/project.pbxproj @@ -161,7 +161,7 @@ 137ACA4C1A9EEFC8006689AC /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0820; + LastUpgradeCheck = 0910; ORGANIZATIONNAME = "Alexandre Leite"; TargetAttributes = { 137ACA531A9EEFC8006689AC = { @@ -250,14 +250,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -280,11 +286,12 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.1; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = ""; TARGETED_DEVICE_FAMILY = "1,2"; }; name = Debug; @@ -297,14 +304,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -320,10 +333,11 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 8.1; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = ""; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -338,7 +352,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.al7dev.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -351,7 +365,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.al7dev.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -371,7 +385,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.al7dev.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ALSpotlightView.app/ALSpotlightView"; }; name = Debug; @@ -388,7 +402,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.al7dev.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/ALSpotlightView.app/ALSpotlightView"; }; name = Release; diff --git a/ALSpotlightView/Source/ALSpotlightView.swift b/ALSpotlightView/Source/ALSpotlightView.swift index ca57ae1..33158cf 100644 --- a/ALSpotlightView/Source/ALSpotlightView.swift +++ b/ALSpotlightView/Source/ALSpotlightView.swift @@ -151,7 +151,7 @@ open class ALSpotlightView: UIView { //MARK- Action Targets - func onSpotlightViewTap(_ sender: UITapGestureRecognizer) { + @objc func onSpotlightViewTap(_ sender: UITapGestureRecognizer) { if let handler = self.onTapHandler { handler() } diff --git a/ALSpotlightView/ViewController.swift b/ALSpotlightView/ViewController.swift index 8c1b67f..38b4e68 100644 --- a/ALSpotlightView/ViewController.swift +++ b/ALSpotlightView/ViewController.swift @@ -33,7 +33,7 @@ class ViewController: UIViewController { //MARK- Tap Gesture Recognizer - func onTap(_ sender: UITapGestureRecognizer) { + @objc func onTap(_ sender: UITapGestureRecognizer) { let location = sender.location(in: self.view) var spotlightCenter = CGPoint.zero spotlightCenter.x = location.x / self.view.bounds.size.width