From f06e5c6b3363dc05730ae0d54a7ffaa4037dd9be Mon Sep 17 00:00:00 2001 From: BOOMik Date: Mon, 16 Nov 2015 01:56:24 +0300 Subject: [PATCH 01/14] Support save image proporties. Don't show shadow w/o images. --- TVButton/TVButton.swift | 87 ++++++++++++++++++++++++++------ TVButton/TVButtonConstants.swift | 5 +- 2 files changed, 76 insertions(+), 16 deletions(-) diff --git a/TVButton/TVButton.swift b/TVButton/TVButton.swift index d92690b..079e331 100644 --- a/TVButton/TVButton.swift +++ b/TVButton/TVButton.swift @@ -50,20 +50,28 @@ public class TVButton: UIButton, UIGestureRecognizerDelegate { subview.removeFromSuperview() } // Instantiate an imageview with corners for every layer - for layer in layers! { - let imageView = UIImageView(image: layer.internalImage) - imageView.layer.cornerRadius = cornerRadius - imageView.clipsToBounds = true - imageView.layer.needsDisplayOnBoundsChange = true - containerView.addSubview(imageView) + if (layers != nil && layers!.count > 0) { + for layer in layers! { + let imageView = UIImageView(image: layer.internalImage) + imageView.layer.cornerRadius = cornerRadius + imageView.clipsToBounds = true + imageView.layer.needsDisplayOnBoundsChange = true + if saveAspect { + imageView.contentMode = .ScaleAspectFill + } + containerView.addSubview(imageView) + } + // Add specular shine effect + let frameworkBundle = NSBundle(forClass: TVButton.self) + let specularViewPath = frameworkBundle.pathForResource("Specular", ofType: "png") + specularView.image = UIImage(contentsOfFile: specularViewPath!) + updateFrame() + self.containerView.addSubview(specularView) } - // Add specular shine effect - let frameworkBundle = NSBundle(forClass: TVButton.self) - let specularViewPath = frameworkBundle.pathForResource("Specular", ofType: "png") - specularView.image = UIImage(contentsOfFile:specularViewPath!) - self.containerView.addSubview(specularView) } } + /// True if need save image aspect + public var saveAspect: Bool = defaultSaveAspect /// Determines the intensity of the parallax depth effect. Default is 1.0. public var parallaxIntensity: CGFloat = defaultParallaxIntensity @@ -100,9 +108,12 @@ public class TVButton: UIButton, UIGestureRecognizerDelegate { super.layoutSubviews() containerView.frame = self.bounds self.layer.masksToBounds = false; - let shadowPath = UIBezierPath(roundedRect: self.bounds, cornerRadius: cornerRadius) - self.layer.shadowPath = shadowPath.CGPath - + if (containerView.subviews.count > 0) { + let shadowPath = UIBezierPath(roundedRect: self.bounds, cornerRadius: cornerRadius) + self.layer.shadowPath = shadowPath.CGPath + } else { + self.layer.shadowPath = nil + } // Stop here if animation is on if let animation = tvButtonAnimation { if animation.highlightMode == true { @@ -119,6 +130,7 @@ public class TVButton: UIButton, UIGestureRecognizerDelegate { subview.frame = CGRect(origin: subview.frame.origin, size: containerView.frame.size) } } + updateFrame() } /** @@ -216,5 +228,50 @@ public class TVButton: UIButton, UIGestureRecognizerDelegate { public func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool { return true } - + + + func getScaledSizeOfImage(image: UIImage, toSize: CGSize) -> CGSize + { + let widthRatio = toSize.width/image.size.width + let heightRatio = toSize.height/image.size.height + let scale = min(widthRatio, heightRatio) + let imageWidth = scale*image.size.width + let imageHeight = scale*image.size.height + return CGSizeMake(imageWidth, imageHeight) + } + + + + public func updateFrame() { + if (saveAspect && layers != nil && layers!.count > 0) { + var newSize:CGSize = getScaledSizeOfImage(layers![0].internalImage!, toSize: self.frame.size) + + var frame = self.frame + + if let sv = self.superview { + if (sv.frame.width != 0 && sv.frame.height != 0 ) { + newSize = getScaledSizeOfImage(layers![0].internalImage!, toSize: sv.frame.size) + frame = sv.frame + } + } + + + var svframe = specularView.frame; + svframe.size = newSize + specularView.frame = svframe; + + + let x = (frame.width - newSize.width) / 2 + let y = (frame.height - newSize.height) / 2 + + frame.origin.x = x + frame.origin.y = y + + frame.size = newSize + self.frame = frame; + self.layoutIfNeeded() + } + } + + } \ No newline at end of file diff --git a/TVButton/TVButtonConstants.swift b/TVButton/TVButtonConstants.swift index b0d8d8a..502d78f 100644 --- a/TVButton/TVButtonConstants.swift +++ b/TVButton/TVButtonConstants.swift @@ -51,4 +51,7 @@ let shadowFactor: CGFloat = 10 let specularScale: CGFloat = 2.0 // The scale of the specular shine -let specularAlpha: CGFloat = 0.25 \ No newline at end of file +let specularAlpha: CGFloat = 0.25 + +// If need save aspect +let defaultSaveAspect : Bool = false \ No newline at end of file From 0cf10b735ce3c893f25de564202bf7ee815ba80e Mon Sep 17 00:00:00 2001 From: BOOMik Date: Mon, 16 Nov 2015 03:14:19 +0300 Subject: [PATCH 02/14] Support custom specular image --- TVButton/TVButton.swift | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/TVButton/TVButton.swift b/TVButton/TVButton.swift index 079e331..c2c2eb5 100644 --- a/TVButton/TVButton.swift +++ b/TVButton/TVButton.swift @@ -62,15 +62,21 @@ public class TVButton: UIButton, UIGestureRecognizerDelegate { containerView.addSubview(imageView) } // Add specular shine effect - let frameworkBundle = NSBundle(forClass: TVButton.self) - let specularViewPath = frameworkBundle.pathForResource("Specular", ofType: "png") - specularView.image = UIImage(contentsOfFile: specularViewPath!) + if let specularImage = customSpecularImage { + specularView.image = specularImage + } else { + let frameworkBundle = NSBundle(forClass: TVButton.self) + let specularViewPath = frameworkBundle.pathForResource("Specular", ofType: "png") + specularView.image = UIImage(contentsOfFile: specularViewPath!) + } updateFrame() self.containerView.addSubview(specularView) } } } /// True if need save image aspect + public var customSpecularImage: UIImage? + /// True if need save image aspect public var saveAspect: Bool = defaultSaveAspect /// Determines the intensity of the parallax depth effect. Default is 1.0. From e152f0a794627a1dbdc5c103cff29839635aa36f Mon Sep 17 00:00:00 2001 From: BOOMik Date: Mon, 16 Nov 2015 03:38:03 +0300 Subject: [PATCH 03/14] Update README --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 7cf1f2a..af24983 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,16 @@ You can customize the parallax intensity of your TVButton. Default value is 1.0 tvButton.parallaxIntensity = 1.3 ``` +If you want to keep the image proportions +```swift + tvButton.saveAspect= 1.3 +``` + +For custom specular image set UIImage to +```swift + tvButton.customSpecularImage +``` + ![TVButton in action](http://i.giphy.com/l0O9zc8b49oDi209y.gif) Enjoy! From 7da35777c0ded70baf03880233d23bc06118e028 Mon Sep 17 00:00:00 2001 From: Kirill Ashikhmin Date: Mon, 21 Mar 2016 23:36:17 +0300 Subject: [PATCH 04/14] Update TVButton.podspec --- TVButton.podspec | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/TVButton.podspec b/TVButton.podspec index 8a2e68a..1a386a9 100644 --- a/TVButton.podspec +++ b/TVButton.podspec @@ -7,8 +7,8 @@ # Pod::Spec.new do |s| - s.name = "TVButton" - s.version = "0.1.5" + s.name = "TVButton Fork" + s.version = "0.1.6" s.summary = "Apple TV style parallax icons as iOS UIButtons" # This description is used to generate tags and improve search results. @@ -17,14 +17,14 @@ Pod::Spec.new do |s| # * Write the description between the DESC delimiters below. # * Finally, don't worry about the indent, CocoaPods strips it! s.description = <<-DESC - Recreating the cool parallax icons from Apple TV as iOS UIButtons (in Swift). + Recreating the cool parallax icons from Apple TV as iOS UIButtons (in Swift). Fork. DESC s.homepage = "https://github.com/marmelroy/TVButton" # s.screenshots = "www.example.com/screenshots_1", "www.example.com/screenshots_2" s.license = 'MIT' s.author = { "Roy Marmelstein" => "marmelroy@gmail.com" } - s.source = { :git => "https://github.com/marmelroy/TVButton.git", :tag => s.version.to_s } + s.source = { :git => "https://github.com/BOOMik/TVButton.git", :tag => s.version.to_s } s.social_media_url = "http://twitter.com/marmelroy" s.platform = :ios, '8.0' From 110070c2549732382ed83abb11ad6ca0cc9318eb Mon Sep 17 00:00:00 2001 From: Kirill Ashikhmin Date: Mon, 21 Mar 2016 23:37:08 +0300 Subject: [PATCH 05/14] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index af24983..b0b9de4 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ tvButton.parallaxIntensity = 1.3 If you want to keep the image proportions ```swift - tvButton.saveAspect= 1.3 + tvButton.saveAspect= true ``` For custom specular image set UIImage to From 7bbb1153fea2757110c59991c8673b32aeaae5af Mon Sep 17 00:00:00 2001 From: Kirill Ashikhmin Date: Mon, 21 Mar 2016 23:57:44 +0300 Subject: [PATCH 06/14] no message --- TVButton.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TVButton.podspec b/TVButton.podspec index 1a386a9..da5b78f 100644 --- a/TVButton.podspec +++ b/TVButton.podspec @@ -7,7 +7,7 @@ # Pod::Spec.new do |s| - s.name = "TVButton Fork" + s.name = "TVButton BOOMik Fork" s.version = "0.1.6" s.summary = "Apple TV style parallax icons as iOS UIButtons" From ed88cd8b9701094eed29b84506a3e16a7298638e Mon Sep 17 00:00:00 2001 From: Kirill Ashikhmin Date: Tue, 22 Mar 2016 00:11:30 +0300 Subject: [PATCH 07/14] no message --- TVButton.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TVButton.podspec b/TVButton.podspec index da5b78f..120b264 100644 --- a/TVButton.podspec +++ b/TVButton.podspec @@ -17,7 +17,7 @@ Pod::Spec.new do |s| # * Write the description between the DESC delimiters below. # * Finally, don't worry about the indent, CocoaPods strips it! s.description = <<-DESC - Recreating the cool parallax icons from Apple TV as iOS UIButtons (in Swift). Fork. + Recreating the cool parallax icons from Apple TV as iOS UIButtons (in Swift). DESC s.homepage = "https://github.com/marmelroy/TVButton" @@ -35,4 +35,4 @@ Pod::Spec.new do |s| # s.public_header_files = 'Pod/Classes/**/*.h' # s.dependency 'AFNetworking', '~> 2.3' -end +end From f3e4b0e0e7b5da3a49426b564668fd18c4ba0cf8 Mon Sep 17 00:00:00 2001 From: Kirill Ashikhmin Date: Tue, 22 Mar 2016 00:19:57 +0300 Subject: [PATCH 08/14] no message --- TVButton.podspec | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/TVButton.podspec b/TVButton.podspec index 120b264..eb63259 100644 --- a/TVButton.podspec +++ b/TVButton.podspec @@ -7,32 +7,32 @@ # Pod::Spec.new do |s| - s.name = "TVButton BOOMik Fork" - s.version = "0.1.6" - s.summary = "Apple TV style parallax icons as iOS UIButtons" +s.name = 'TVButton' +s.version = '0'.1.5' +s.summary = 'Apple TV style parallax icons as iOS UIButtons' # This description is used to generate tags and improve search results. # * Think: What does it do? Why did you write it? What is the focus? # * Try to keep it short, snappy and to the point. # * Write the description between the DESC delimiters below. # * Finally, don't worry about the indent, CocoaPods strips it! - s.description = <<-DESC - Recreating the cool parallax icons from Apple TV as iOS UIButtons (in Swift). - DESC +s.description = <<-DESC +Recreating the cool parallax icons from Apple TV as iOS UIButtons (in Swift). +DESC - s.homepage = "https://github.com/marmelroy/TVButton" - # s.screenshots = "www.example.com/screenshots_1", "www.example.com/screenshots_2" - s.license = 'MIT' - s.author = { "Roy Marmelstein" => "marmelroy@gmail.com" } - s.source = { :git => "https://github.com/BOOMik/TVButton.git", :tag => s.version.to_s } - s.social_media_url = "http://twitter.com/marmelroy" +s.homepage = 'https://github.com/marmelroy/TVButton' +# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2' +s.license = 'MIT' +s.author = { 'Roy Marmelstein' => 'marmelroy@gmail.com' } +s.source = { :git => 'https://github.com/marmelroy/TVButton.git', :tag => s.version.to_s } +s.social_media_url = "http://twitter.com/marmelroy" - s.platform = :ios, '8.0' - s.requires_arc = true +s.platform = :ios,'8.0' +s.requires_arc = true - s.source_files = "TVButton" - s.resources = "TVButton/Specular.png" +s.source_files = "TVButton" +s.resources = "TVButton/Specular.png" - # s.public_header_files = 'Pod/Classes/**/*.h' - # s.dependency 'AFNetworking', '~> 2.3' +# s.public_header_files = 'Pod/Classes/**/*.h' +# s.dependency 'AFNetworking', '~> 2.3' end From fdf27aeafed2ee7a15e923940a978107b4d0e593 Mon Sep 17 00:00:00 2001 From: Kirill Ashikhmin Date: Tue, 22 Mar 2016 00:36:52 +0300 Subject: [PATCH 09/14] no message --- TVButton.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TVButton.podspec b/TVButton.podspec index eb63259..818fc64 100644 --- a/TVButton.podspec +++ b/TVButton.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'TVButton' -s.version = '0'.1.5' +s.version = '0.1.6' s.summary = 'Apple TV style parallax icons as iOS UIButtons' # This description is used to generate tags and improve search results. From 90fcba68888fb7e12e758be5d8e3fa57e13c2ab8 Mon Sep 17 00:00:00 2001 From: Kirill Ashikhmin Date: Tue, 22 Mar 2016 00:37:17 +0300 Subject: [PATCH 10/14] no message --- TVButton.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TVButton.podspec b/TVButton.podspec index 818fc64..95533d8 100644 --- a/TVButton.podspec +++ b/TVButton.podspec @@ -24,7 +24,7 @@ s.homepage = 'https://github.com/marmelroy/TVButton' # s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2' s.license = 'MIT' s.author = { 'Roy Marmelstein' => 'marmelroy@gmail.com' } -s.source = { :git => 'https://github.com/marmelroy/TVButton.git', :tag => s.version.to_s } +s.source = { :git => 'https://github.com/BOOMik/TVButton.git', :tag => s.version.to_s } s.social_media_url = "http://twitter.com/marmelroy" s.platform = :ios,'8.0' From 84f7bc650238d29f59af2cd43315dee0677a4107 Mon Sep 17 00:00:00 2001 From: Kirill Ashikhmin Date: Sun, 13 Nov 2016 22:55:08 +0300 Subject: [PATCH 11/14] 0.1.7 Swift 3 --- TVButton.podspec | 2 +- TVButton.xcodeproj/project.pbxproj | 6 +++ TVButton/TVButton.swift | 66 +++++++++++++++--------------- TVButton/TVButtonAnimation.swift | 56 ++++++++++++------------- TVButtonTests/TVButtonTests.swift | 2 +- 5 files changed, 69 insertions(+), 63 deletions(-) diff --git a/TVButton.podspec b/TVButton.podspec index 95533d8..3951835 100644 --- a/TVButton.podspec +++ b/TVButton.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'TVButton' -s.version = '0.1.6' +s.version = '0.1.7' s.summary = 'Apple TV style parallax icons as iOS UIButtons' # This description is used to generate tags and improve search results. diff --git a/TVButton.xcodeproj/project.pbxproj b/TVButton.xcodeproj/project.pbxproj index 7db8493..006356c 100644 --- a/TVButton.xcodeproj/project.pbxproj +++ b/TVButton.xcodeproj/project.pbxproj @@ -176,9 +176,11 @@ TargetAttributes = { 342AA08B1BEEBE6F00B1A7D9 = { CreatedOnToolsVersion = 7.1; + LastSwiftMigration = 0810; }; 342AA0951BEEBE6F00B1A7D9 = { CreatedOnToolsVersion = 7.1; + LastSwiftMigration = 0810; }; }; }; @@ -353,6 +355,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -371,6 +374,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.TVButton; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -381,6 +385,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.TVButtonTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -391,6 +396,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.TVButtonTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/TVButton/TVButton.swift b/TVButton/TVButton.swift index c2c2eb5..e9f3cc1 100644 --- a/TVButton/TVButton.swift +++ b/TVButton/TVButton.swift @@ -29,7 +29,7 @@ public extension TVButtonLayer { /** TVButton Object */ -public class TVButton: UIButton, UIGestureRecognizerDelegate { +open class TVButton: UIButton, UIGestureRecognizerDelegate { // MARK: Internal variables internal var containerView = UIView() @@ -43,7 +43,7 @@ public class TVButton: UIButton, UIGestureRecognizerDelegate { // MARK: Public variables /// Stack of TVButtonLayers inside the button - public var layers: [TVButtonLayer]? { + open var layers: [TVButtonLayer]? { didSet { // Remove existing parallax layer views for subview in containerView.subviews { @@ -57,7 +57,7 @@ public class TVButton: UIButton, UIGestureRecognizerDelegate { imageView.clipsToBounds = true imageView.layer.needsDisplayOnBoundsChange = true if saveAspect { - imageView.contentMode = .ScaleAspectFill + imageView.contentMode = .scaleAspectFill } containerView.addSubview(imageView) } @@ -65,8 +65,8 @@ public class TVButton: UIButton, UIGestureRecognizerDelegate { if let specularImage = customSpecularImage { specularView.image = specularImage } else { - let frameworkBundle = NSBundle(forClass: TVButton.self) - let specularViewPath = frameworkBundle.pathForResource("Specular", ofType: "png") + let frameworkBundle = Bundle(for: TVButton.self) + let specularViewPath = frameworkBundle.path(forResource: "Specular", ofType: "png") specularView.image = UIImage(contentsOfFile: specularViewPath!) } updateFrame() @@ -75,17 +75,17 @@ public class TVButton: UIButton, UIGestureRecognizerDelegate { } } /// True if need save image aspect - public var customSpecularImage: UIImage? + open var customSpecularImage: UIImage? /// True if need save image aspect - public var saveAspect: Bool = defaultSaveAspect + open var saveAspect: Bool = defaultSaveAspect /// Determines the intensity of the parallax depth effect. Default is 1.0. - public var parallaxIntensity: CGFloat = defaultParallaxIntensity + open var parallaxIntensity: CGFloat = defaultParallaxIntensity /// Shadow color for the TVButton. Default is black. - public var shadowColor: UIColor = UIColor.blackColor() { + open var shadowColor: UIColor = UIColor.black { didSet { - self.layer.shadowColor = shadowColor.CGColor + self.layer.shadowColor = shadowColor.cgColor } } @@ -110,13 +110,13 @@ public class TVButton: UIButton, UIGestureRecognizerDelegate { /** Lays out subviews. */ - override public func layoutSubviews() { + override open func layoutSubviews() { super.layoutSubviews() containerView.frame = self.bounds self.layer.masksToBounds = false; if (containerView.subviews.count > 0) { let shadowPath = UIBezierPath(roundedRect: self.bounds, cornerRadius: cornerRadius) - self.layer.shadowPath = shadowPath.CGPath + self.layer.shadowPath = shadowPath.cgPath } else { self.layer.shadowPath = nil } @@ -130,7 +130,7 @@ public class TVButton: UIButton, UIGestureRecognizerDelegate { // Adjust size for every subview for subview in containerView.subviews { if subview == specularView { - subview.frame = CGRect(origin: subview.frame.origin, size: CGSizeMake(specularScale * containerView.frame.size.width, specularScale * containerView.frame.size.height)) + subview.frame = CGRect(origin: subview.frame.origin, size: CGSize(width: specularScale * containerView.frame.size.width, height: specularScale * containerView.frame.size.height)) } else { subview.frame = CGRect(origin: subview.frame.origin, size: containerView.frame.size) @@ -143,15 +143,15 @@ public class TVButton: UIButton, UIGestureRecognizerDelegate { Button setup. Conducted on init. */ func setup() { - containerView.userInteractionEnabled = false + containerView.isUserInteractionEnabled = false self.addSubview(containerView) containerView.clipsToBounds = true containerView.layer.cornerRadius = cornerRadius self.clipsToBounds = true specularView.alpha = 0.0 - specularView.contentMode = UIViewContentMode.ScaleAspectFill + specularView.contentMode = UIViewContentMode.scaleAspectFill self.layer.shadowRadius = self.bounds.size.height/(2*shadowFactor) - self.layer.shadowOffset = CGSizeMake(0.0, shadowFactor/3) + self.layer.shadowOffset = CGSize(width: 0.0, height: shadowFactor/3) self.layer.shadowOpacity = 0.5; tvButtonAnimation = TVButtonAnimation(button: self) self.addGestureRecognizers() @@ -164,12 +164,12 @@ public class TVButton: UIButton, UIGestureRecognizerDelegate { Adds the gesture recognizers to the button. */ func addGestureRecognizers(){ - panGestureRecognizer = UIPanGestureRecognizer(target: self, action: "handlePan:") + panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(TVButton.handlePan(_:))) panGestureRecognizer?.delegate = self self.addGestureRecognizer(panGestureRecognizer!) - tapGestureRecognizer = UITapGestureRecognizer(target: self, action: "handleTap:") + tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(TVButton.handleTap(_:))) self.addGestureRecognizer(tapGestureRecognizer!) - longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: "handleLongPress:") + longPressGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(TVButton.handleLongPress(_:))) longPressGestureRecognizer?.delegate = self self.addGestureRecognizer(longPressGestureRecognizer!) } @@ -178,7 +178,7 @@ public class TVButton: UIButton, UIGestureRecognizerDelegate { Pan gesture recognizer handler. - Parameter gestureRecognizer: TVButton's UIPanGestureRecognizer. */ - func handlePan(gestureRecognizer: UIGestureRecognizer) { + func handlePan(_ gestureRecognizer: UIGestureRecognizer) { self.gestureRecognizerDidUpdate(gestureRecognizer) } @@ -186,7 +186,7 @@ public class TVButton: UIButton, UIGestureRecognizerDelegate { Long press gesture recognizer handler. - Parameter gestureRecognizer: TVButton's UILongPressGestureRecognizer. */ - func handleLongPress(gestureRecognizer: UIGestureRecognizer) { + func handleLongPress(_ gestureRecognizer: UIGestureRecognizer) { self.gestureRecognizerDidUpdate(gestureRecognizer) } @@ -194,29 +194,29 @@ public class TVButton: UIButton, UIGestureRecognizerDelegate { Tap gesture recognizer handler. Sends TouchUpInside to super. - Parameter gestureRecognizer: TVButton's UITapGestureRecognizer. */ - func handleTap(gestureRecognizer: UIGestureRecognizer) { - super.sendActionsForControlEvents(UIControlEvents.TouchUpInside) + func handleTap(_ gestureRecognizer: UIGestureRecognizer) { + super.sendActions(for: UIControlEvents.touchUpInside) } /** Determines button's reaction to gesturerecognizer. - Parameter gestureRecognizer: either UITapGestureRecognizer or UILongPressGestureRecognizer. */ - func gestureRecognizerDidUpdate(gestureRecognizer: UIGestureRecognizer){ + func gestureRecognizerDidUpdate(_ gestureRecognizer: UIGestureRecognizer){ if layers == nil { return } - let point = gestureRecognizer.locationInView(self) + let point = gestureRecognizer.location(in: self) if let animation = tvButtonAnimation { - if gestureRecognizer.state == .Began { + if gestureRecognizer.state == .began { animation.enterMovement() animation.processMovement(point) } - else if gestureRecognizer.state == .Changed { + else if gestureRecognizer.state == .changed { animation.processMovement(point) } else { - if gestureRecognizer.state == .Began || gestureRecognizer.state == .Changed { + if gestureRecognizer.state == .began || gestureRecognizer.state == .changed { return } animation.exitMovement() @@ -231,24 +231,24 @@ public class TVButton: UIButton, UIGestureRecognizerDelegate { - Parameter gestureRecognizer: First gestureRecognizer. - Parameter otherGestureRecognizer: Second gestureRecognizer. */ - public func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool { + open func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { return true } - func getScaledSizeOfImage(image: UIImage, toSize: CGSize) -> CGSize + func getScaledSizeOfImage(_ image: UIImage, toSize: CGSize) -> CGSize { let widthRatio = toSize.width/image.size.width let heightRatio = toSize.height/image.size.height let scale = min(widthRatio, heightRatio) let imageWidth = scale*image.size.width let imageHeight = scale*image.size.height - return CGSizeMake(imageWidth, imageHeight) + return CGSize(width: imageWidth, height: imageHeight) } - public func updateFrame() { + open func updateFrame() { if (saveAspect && layers != nil && layers!.count > 0) { var newSize:CGSize = getScaledSizeOfImage(layers![0].internalImage!, toSize: self.frame.size) @@ -280,4 +280,4 @@ public class TVButton: UIButton, UIGestureRecognizerDelegate { } -} \ No newline at end of file +} diff --git a/TVButton/TVButtonAnimation.swift b/TVButton/TVButtonAnimation.swift index dc8bf0a..566b241 100644 --- a/TVButton/TVButtonAnimation.swift +++ b/TVButton/TVButtonAnimation.swift @@ -31,33 +31,33 @@ internal class TVButtonAnimation { } if let tvButton = button { self.highlightMode = true - let targetShadowOffset = CGSizeMake(0.0, tvButton.bounds.size.height/shadowFactor) + let targetShadowOffset = CGSize(width: 0.0, height: tvButton.bounds.size.height/shadowFactor) tvButton.layer.removeAllAnimations() CATransaction.begin() CATransaction.setCompletionBlock({ () -> Void in tvButton.layer.shadowOffset = targetShadowOffset }) let shaowOffsetAnimation = CABasicAnimation(keyPath: "shadowOffset") - shaowOffsetAnimation.toValue = NSValue(CGSize: targetShadowOffset) + shaowOffsetAnimation.toValue = NSValue(cgSize: targetShadowOffset) shaowOffsetAnimation.duration = animationDuration - shaowOffsetAnimation.removedOnCompletion = false + shaowOffsetAnimation.isRemovedOnCompletion = false shaowOffsetAnimation.fillMode = kCAFillModeForwards shaowOffsetAnimation.timingFunction = CAMediaTimingFunction(name: "easeOut") - tvButton.layer.addAnimation(shaowOffsetAnimation, forKey: "shadowOffset") + tvButton.layer.add(shaowOffsetAnimation, forKey: "shadowOffset") CATransaction.commit() let shadowOpacityAnimation = CABasicAnimation(keyPath: "shadowOpacity") shadowOpacityAnimation.toValue = 0.6 shadowOpacityAnimation.duration = animationDuration - shadowOpacityAnimation.removedOnCompletion = false + shadowOpacityAnimation.isRemovedOnCompletion = false shadowOpacityAnimation.fillMode = kCAFillModeForwards shadowOpacityAnimation.timingFunction = CAMediaTimingFunction(name: "easeOut") - tvButton.layer.addAnimation(shadowOpacityAnimation, forKey: "shadowOpacityAnimation") + tvButton.layer.add(shadowOpacityAnimation, forKey: "shadowOpacityAnimation") CATransaction.commit() } } // Movement continues - func processMovement(point: CGPoint){ + func processMovement(_ point: CGPoint){ if (highlightMode == false) { return } @@ -84,28 +84,28 @@ internal class TVButtonAnimation { let targetScaleTransform = CATransform3DMakeScale(highlightedScale, highlightedScale, highlightedScale) let combinedTransform = CATransform3DConcat(combinedRotateTranslateTransform, targetScaleTransform) - UIView.animateWithDuration(animationDuration, delay: 0.0, options: UIViewAnimationOptions.CurveEaseOut, animations: { () -> Void in + UIView.animate(withDuration: animationDuration, delay: 0.0, options: UIViewAnimationOptions.curveEaseOut, animations: { () -> Void in tvButton.layer.transform = combinedTransform tvButton.specularView.alpha = specularAlpha tvButton.specularView.center = point - for var i = 1; i < tvButton.containerView.subviews.count ; i++ { + for i in 1 ..< tvButton.containerView.subviews.count { let adjusted = i/2 let scale = 1 + maxScaleDelta*CGFloat(adjusted/tvButton.containerView.subviews.count) let subview = tvButton.containerView.subviews[i] if subview != tvButton.specularView { - subview.contentMode = UIViewContentMode.Redraw - subview.frame.size = CGSizeMake(tvButton.bounds.size.width*scale, tvButton.bounds.size.height*scale) + subview.contentMode = UIViewContentMode.redraw + subview.frame.size = CGSize(width: tvButton.bounds.size.width*scale, height: tvButton.bounds.size.height*scale) } } }, completion: nil) - UIView.animateWithDuration(0.16, delay: 0.0, options: UIViewAnimationOptions.CurveEaseOut, animations: { () -> Void in - for var i = 1; i < tvButton.containerView.subviews.count ; i++ { + UIView.animate(withDuration: 0.16, delay: 0.0, options: UIViewAnimationOptions.curveEaseOut, animations: { () -> Void in + for i in 1 ..< tvButton.containerView.subviews.count { let subview = tvButton.containerView.subviews[i] let xParallax = tvButton.parallaxIntensity*parallaxIntensityXFactor let yParallax = tvButton.parallaxIntensity*parallaxIntensityYFactor if subview != tvButton.specularView { - subview.center = CGPointMake(tvButton.bounds.size.width/2 + xTranslation*CGFloat(i)*xParallax, tvButton.bounds.size.height/2 + yTranslation*CGFloat(i)*0.3*yParallax) + subview.center = CGPoint(x: tvButton.bounds.size.width/2 + xTranslation*CGFloat(i)*xParallax, y: tvButton.bounds.size.height/2 + yTranslation*CGFloat(i)*0.3*yParallax) } } }, completion: nil) @@ -119,7 +119,7 @@ internal class TVButtonAnimation { return } if let tvButton = button { - let targetShadowOffset = CGSizeMake(0.0, shadowFactor/3) + let targetShadowOffset = CGSize(width: 0.0, height: shadowFactor/3) let targetScaleTransform = CATransform3DMakeScale(1.0, 1.0, 1.0) tvButton.specularView.layer.removeAllAnimations() CATransaction.begin() @@ -129,27 +129,27 @@ internal class TVButtonAnimation { self.highlightMode = false }) let shaowOffsetAnimation = CABasicAnimation(keyPath: "shadowOffset") - shaowOffsetAnimation.toValue = NSValue(CGSize: targetShadowOffset) + shaowOffsetAnimation.toValue = NSValue(cgSize: targetShadowOffset) shaowOffsetAnimation.duration = animationDuration shaowOffsetAnimation.fillMode = kCAFillModeForwards - shaowOffsetAnimation.removedOnCompletion = false + shaowOffsetAnimation.isRemovedOnCompletion = false shaowOffsetAnimation.timingFunction = CAMediaTimingFunction(name: "easeOut") - tvButton.layer.addAnimation(shaowOffsetAnimation, forKey: "shadowOffset") + tvButton.layer.add(shaowOffsetAnimation, forKey: "shadowOffset") let scaleAnimation = CABasicAnimation(keyPath: "transform") - scaleAnimation.toValue = NSValue(CATransform3D: targetScaleTransform) + scaleAnimation.toValue = NSValue(caTransform3D: targetScaleTransform) scaleAnimation.duration = animationDuration - scaleAnimation.removedOnCompletion = false + scaleAnimation.isRemovedOnCompletion = false scaleAnimation.fillMode = kCAFillModeForwards scaleAnimation.timingFunction = CAMediaTimingFunction(name: "easeOut") - tvButton.layer.addAnimation(scaleAnimation, forKey: "scaleAnimation") + tvButton.layer.add(scaleAnimation, forKey: "scaleAnimation") CATransaction.commit() - UIView.animateWithDuration(animationDuration, delay: 0.0, options: UIViewAnimationOptions.CurveEaseOut, animations: { () -> Void in - tvButton.transform = CGAffineTransformIdentity + UIView.animate(withDuration: animationDuration, delay: 0.0, options: UIViewAnimationOptions.curveEaseOut, animations: { () -> Void in + tvButton.transform = CGAffineTransform.identity tvButton.specularView.alpha = 0.0 - for var i = 0; i < tvButton.containerView.subviews.count ; i++ { + for i in 0 ..< tvButton.containerView.subviews.count { let subview = tvButton.containerView.subviews[i] - subview.frame.size = CGSizeMake(tvButton.bounds.size.width, tvButton.bounds.size.height) - subview.center = CGPointMake(tvButton.bounds.size.width/2, tvButton.bounds.size.height/2) + subview.frame.size = CGSize(width: tvButton.bounds.size.width, height: tvButton.bounds.size.height) + subview.center = CGPoint(x: tvButton.bounds.size.width/2, y: tvButton.bounds.size.height/2) } }, completion:nil) } @@ -157,8 +157,8 @@ internal class TVButtonAnimation { // MARK: Convenience - func degreesToRadians(value:CGFloat) -> CGFloat { + func degreesToRadians(_ value:CGFloat) -> CGFloat { return value * CGFloat(M_PI) / 180.0 } -} \ No newline at end of file +} diff --git a/TVButtonTests/TVButtonTests.swift b/TVButtonTests/TVButtonTests.swift index b7645bc..3c042f3 100644 --- a/TVButtonTests/TVButtonTests.swift +++ b/TVButtonTests/TVButtonTests.swift @@ -28,7 +28,7 @@ class TVButtonTests: 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. } } From f7abac664d7c427b7883bebfd1f8852faa8cdb26 Mon Sep 17 00:00:00 2001 From: Kirill Ashikhmin Date: Mon, 2 Jan 2017 02:38:04 +0300 Subject: [PATCH 12/14] 0.1.8 --- TVButton.podspec | 19 +--------------- TVButton.xcodeproj/project.pbxproj | 26 +++++---------------- TVButton/Info.plist | 4 ++-- TVButton/TVButtonConstants.swift | 2 +- TVButtonTests/Info.plist | 24 -------------------- TVButtonTests/TVButtonTests.swift | 36 ------------------------------ 6 files changed, 10 insertions(+), 101 deletions(-) delete mode 100644 TVButtonTests/Info.plist delete mode 100644 TVButtonTests/TVButtonTests.swift diff --git a/TVButton.podspec b/TVButton.podspec index 3951835..e9108f3 100644 --- a/TVButton.podspec +++ b/TVButton.podspec @@ -1,38 +1,21 @@ -# -# Be sure to run `pod lib lint TVButton.podspec' to ensure this is a -# valid spec before submitting. -# -# Any lines starting with a # are optional, but their use is encouraged -# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html -# - Pod::Spec.new do |s| s.name = 'TVButton' -s.version = '0.1.7' +s.version = '0.1.8' s.summary = 'Apple TV style parallax icons as iOS UIButtons' -# This description is used to generate tags and improve search results. -# * Think: What does it do? Why did you write it? What is the focus? -# * Try to keep it short, snappy and to the point. -# * Write the description between the DESC delimiters below. -# * Finally, don't worry about the indent, CocoaPods strips it! s.description = <<-DESC Recreating the cool parallax icons from Apple TV as iOS UIButtons (in Swift). DESC s.homepage = 'https://github.com/marmelroy/TVButton' -# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2' s.license = 'MIT' s.author = { 'Roy Marmelstein' => 'marmelroy@gmail.com' } s.source = { :git => 'https://github.com/BOOMik/TVButton.git', :tag => s.version.to_s } s.social_media_url = "http://twitter.com/marmelroy" s.platform = :ios,'8.0' -s.requires_arc = true s.source_files = "TVButton" s.resources = "TVButton/Specular.png" -# s.public_header_files = 'Pod/Classes/**/*.h' -# s.dependency 'AFNetworking', '~> 2.3' end diff --git a/TVButton.xcodeproj/project.pbxproj b/TVButton.xcodeproj/project.pbxproj index 006356c..1ed751d 100644 --- a/TVButton.xcodeproj/project.pbxproj +++ b/TVButton.xcodeproj/project.pbxproj @@ -9,7 +9,6 @@ /* Begin PBXBuildFile section */ 342AA0901BEEBE6F00B1A7D9 /* TVButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 342AA08F1BEEBE6F00B1A7D9 /* TVButton.h */; settings = {ATTRIBUTES = (Public, ); }; }; 342AA0971BEEBE6F00B1A7D9 /* TVButton.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 342AA08C1BEEBE6F00B1A7D9 /* TVButton.framework */; }; - 342AA09C1BEEBE6F00B1A7D9 /* TVButtonTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 342AA09B1BEEBE6F00B1A7D9 /* TVButtonTests.swift */; }; 342AA0A71BEEBF6E00B1A7D9 /* TVButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 342AA0A61BEEBF6E00B1A7D9 /* TVButton.swift */; }; 342AA0A91BEEBF7500B1A7D9 /* Specular.png in Resources */ = {isa = PBXBuildFile; fileRef = 342AA0A81BEEBF7500B1A7D9 /* Specular.png */; }; 34F374BE1BF1B0890085BE13 /* TVButtonAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34F374BD1BF1B0890085BE13 /* TVButtonAnimation.swift */; }; @@ -31,8 +30,6 @@ 342AA08F1BEEBE6F00B1A7D9 /* TVButton.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TVButton.h; sourceTree = ""; }; 342AA0911BEEBE6F00B1A7D9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 342AA0961BEEBE6F00B1A7D9 /* TVButtonTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TVButtonTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 342AA09B1BEEBE6F00B1A7D9 /* TVButtonTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TVButtonTests.swift; sourceTree = ""; }; - 342AA09D1BEEBE6F00B1A7D9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 342AA0A61BEEBF6E00B1A7D9 /* TVButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TVButton.swift; sourceTree = ""; }; 342AA0A81BEEBF7500B1A7D9 /* Specular.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Specular.png; sourceTree = ""; }; 34F374BD1BF1B0890085BE13 /* TVButtonAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TVButtonAnimation.swift; sourceTree = ""; }; @@ -62,7 +59,6 @@ isa = PBXGroup; children = ( 342AA08E1BEEBE6F00B1A7D9 /* TVButton */, - 342AA09A1BEEBE6F00B1A7D9 /* TVButtonTests */, 342AA08D1BEEBE6F00B1A7D9 /* Products */, ); sourceTree = ""; @@ -87,15 +83,6 @@ path = TVButton; sourceTree = ""; }; - 342AA09A1BEEBE6F00B1A7D9 /* TVButtonTests */ = { - isa = PBXGroup; - children = ( - 342AA09B1BEEBE6F00B1A7D9 /* TVButtonTests.swift */, - 342AA09D1BEEBE6F00B1A7D9 /* Info.plist */, - ); - path = TVButtonTests; - sourceTree = ""; - }; 34F374CE1BF1B7EE0085BE13 /* Sources */ = { isa = PBXGroup; children = ( @@ -176,11 +163,11 @@ TargetAttributes = { 342AA08B1BEEBE6F00B1A7D9 = { CreatedOnToolsVersion = 7.1; - LastSwiftMigration = 0810; + LastSwiftMigration = 0820; }; 342AA0951BEEBE6F00B1A7D9 = { CreatedOnToolsVersion = 7.1; - LastSwiftMigration = 0810; + LastSwiftMigration = 0820; }; }; }; @@ -235,7 +222,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 342AA09C1BEEBE6F00B1A7D9 /* TVButtonTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -287,7 +273,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.1; + IPHONEOS_DEPLOYMENT_TARGET = 10.2; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -329,7 +315,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.1; + IPHONEOS_DEPLOYMENT_TARGET = 10.2; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; TARGETED_DEVICE_FAMILY = "1,2"; @@ -349,7 +335,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = TVButton/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.1; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.TVButton; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -369,7 +355,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = TVButton/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 10.1; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.TVButton; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/TVButton/Info.plist b/TVButton/Info.plist index 2429c6d..03121ac 100644 --- a/TVButton/Info.plist +++ b/TVButton/Info.plist @@ -15,11 +15,11 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.1.5 + 0.1.8 CFBundleSignature ???? CFBundleVersion - 7 + 17 NSPrincipalClass diff --git a/TVButton/TVButtonConstants.swift b/TVButton/TVButtonConstants.swift index 502d78f..05734bc 100644 --- a/TVButton/TVButtonConstants.swift +++ b/TVButton/TVButtonConstants.swift @@ -54,4 +54,4 @@ let specularScale: CGFloat = 2.0 let specularAlpha: CGFloat = 0.25 // If need save aspect -let defaultSaveAspect : Bool = false \ No newline at end of file +let defaultSaveAspect : Bool = false diff --git a/TVButtonTests/Info.plist b/TVButtonTests/Info.plist deleted file mode 100644 index 3b4743b..0000000 --- a/TVButtonTests/Info.plist +++ /dev/null @@ -1,24 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - BNDL - CFBundleShortVersionString - 0.1.5 - CFBundleSignature - ???? - CFBundleVersion - 7 - - diff --git a/TVButtonTests/TVButtonTests.swift b/TVButtonTests/TVButtonTests.swift deleted file mode 100644 index 3c042f3..0000000 --- a/TVButtonTests/TVButtonTests.swift +++ /dev/null @@ -1,36 +0,0 @@ -// -// TVButtonTests.swift -// TVButtonTests -// -// Created by Roy Marmelstein on 08/11/2015. -// Copyright © 2015 Roy Marmelstein. All rights reserved. -// - -import XCTest -@testable import TVButton - -class TVButtonTests: XCTestCase { - - override func setUp() { - super.setUp() - // Put setup code here. This method is called before the invocation of each test method in the class. - } - - override func tearDown() { - // Put teardown code here. This method is called after the invocation of each test method in the class. - super.tearDown() - } - - func testExample() { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct results. - } - - func testPerformanceExample() { - // This is an example of a performance test case. - self.measure { - // Put the code you want to measure the time of here. - } - } - -} From 67638b5c8612466bbf5ac4d116ced8fa9cecb6be Mon Sep 17 00:00:00 2001 From: Kirill Ashikhmin Date: Thu, 5 Jan 2017 03:58:58 +0300 Subject: [PATCH 13/14] 0.1.9 Deployment target is 8.0 --- .travis.yml | 8 +++----- TVButton.xcodeproj/project.pbxproj | 4 ++-- TVButton/Info.plist | 4 +++- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4340e4a..ba1065e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,11 @@ -osx_image: xcode7.1 +osx_image: xcode8.1 language: objective-c env: global: - LC_CTYPE=en_US.UTF-8 - LANG=en_US.UTF-8 before_install: - - brew update || brew update - - brew outdated xctool || brew upgrade xctool - - gem install cocoapods + - gem install cocoapods --pre - xcrun simctl list install: echo "<3" env: @@ -18,4 +16,4 @@ script: ./build.sh $MODE # whitelist branches: only: - - master + - master \ No newline at end of file diff --git a/TVButton.xcodeproj/project.pbxproj b/TVButton.xcodeproj/project.pbxproj index 1ed751d..2eda685 100644 --- a/TVButton.xcodeproj/project.pbxproj +++ b/TVButton.xcodeproj/project.pbxproj @@ -335,7 +335,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = TVButton/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 10.1; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.TVButton; PRODUCT_NAME = "$(TARGET_NAME)"; @@ -355,7 +355,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = TVButton/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 10.1; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.roymarmelstein.TVButton; PRODUCT_NAME = "$(TARGET_NAME)"; diff --git a/TVButton/Info.plist b/TVButton/Info.plist index 03121ac..2af54bc 100644 --- a/TVButton/Info.plist +++ b/TVButton/Info.plist @@ -15,12 +15,14 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.1.8 + 0.1.9 CFBundleSignature ???? CFBundleVersion 17 NSPrincipalClass + MinimumOSVersion + 8.0 From c6e96101f43f17d2a567cfc6bd03cc2ae8f14074 Mon Sep 17 00:00:00 2001 From: Kirill Ashikhmin Date: Thu, 5 Jan 2017 06:28:57 +0300 Subject: [PATCH 14/14] 1.0.0 Fix crashes --- TVButton/Info.plist | 2 +- TVButton/TVButton.swift | 2 ++ TVButton/TVButtonAnimation.swift | 40 ++++++++++++++++++-------------- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/TVButton/Info.plist b/TVButton/Info.plist index 2af54bc..567c44f 100644 --- a/TVButton/Info.plist +++ b/TVButton/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.1.9 + 1.0.0 CFBundleSignature ???? CFBundleVersion diff --git a/TVButton/TVButton.swift b/TVButton/TVButton.swift index e9f3cc1..53db18a 100644 --- a/TVButton/TVButton.swift +++ b/TVButton/TVButton.swift @@ -49,6 +49,8 @@ open class TVButton: UIButton, UIGestureRecognizerDelegate { for subview in containerView.subviews { subview.removeFromSuperview() } + + // Instantiate an imageview with corners for every layer if (layers != nil && layers!.count > 0) { for layer in layers! { diff --git a/TVButton/TVButtonAnimation.swift b/TVButton/TVButtonAnimation.swift index 566b241..21a7125 100644 --- a/TVButton/TVButtonAnimation.swift +++ b/TVButton/TVButtonAnimation.swift @@ -88,24 +88,28 @@ internal class TVButtonAnimation { tvButton.layer.transform = combinedTransform tvButton.specularView.alpha = specularAlpha tvButton.specularView.center = point - for i in 1 ..< tvButton.containerView.subviews.count { - let adjusted = i/2 - let scale = 1 + maxScaleDelta*CGFloat(adjusted/tvButton.containerView.subviews.count) - let subview = tvButton.containerView.subviews[i] - if subview != tvButton.specularView { - subview.contentMode = UIViewContentMode.redraw - subview.frame.size = CGSize(width: tvButton.bounds.size.width*scale, height: tvButton.bounds.size.height*scale) + if (tvButton.containerView.subviews.count > 0) { + for i in 1 ..< tvButton.containerView.subviews.count { + let adjusted = i/2 + let scale = 1 + maxScaleDelta*CGFloat(adjusted/tvButton.containerView.subviews.count) + let subview = tvButton.containerView.subviews[i] + if subview != tvButton.specularView { + subview.contentMode = UIViewContentMode.redraw + subview.frame.size = CGSize(width: tvButton.bounds.size.width*scale, height: tvButton.bounds. size.height*scale) + } } } }, completion: nil) UIView.animate(withDuration: 0.16, delay: 0.0, options: UIViewAnimationOptions.curveEaseOut, animations: { () -> Void in - for i in 1 ..< tvButton.containerView.subviews.count { - let subview = tvButton.containerView.subviews[i] - let xParallax = tvButton.parallaxIntensity*parallaxIntensityXFactor - let yParallax = tvButton.parallaxIntensity*parallaxIntensityYFactor - if subview != tvButton.specularView { - subview.center = CGPoint(x: tvButton.bounds.size.width/2 + xTranslation*CGFloat(i)*xParallax, y: tvButton.bounds.size.height/2 + yTranslation*CGFloat(i)*0.3*yParallax) + if (tvButton.containerView.subviews.count > 0) { + for i in 1 ..< tvButton.containerView.subviews.count { + let subview = tvButton.containerView.subviews[i] + let xParallax = tvButton.parallaxIntensity*parallaxIntensityXFactor + let yParallax = tvButton.parallaxIntensity*parallaxIntensityYFactor + if subview != tvButton.specularView { + subview.center = CGPoint(x: tvButton.bounds.size.width/2 + xTranslation*CGFloat(i)*xParallax, y: tvButton.bounds.size.height/2 + yTranslation*CGFloat(i)*0.3*yParallax) + } } } }, completion: nil) @@ -146,10 +150,12 @@ internal class TVButtonAnimation { UIView.animate(withDuration: animationDuration, delay: 0.0, options: UIViewAnimationOptions.curveEaseOut, animations: { () -> Void in tvButton.transform = CGAffineTransform.identity tvButton.specularView.alpha = 0.0 - for i in 0 ..< tvButton.containerView.subviews.count { - let subview = tvButton.containerView.subviews[i] - subview.frame.size = CGSize(width: tvButton.bounds.size.width, height: tvButton.bounds.size.height) - subview.center = CGPoint(x: tvButton.bounds.size.width/2, y: tvButton.bounds.size.height/2) + if (tvButton.containerView.subviews.count > 0) { + for i in 0 ..< tvButton.containerView.subviews.count { + let subview = tvButton.containerView.subviews[i] + subview.frame.size = CGSize(width: tvButton.bounds.size.width, height: tvButton.bounds.size.height) + subview.center = CGPoint(x: tvButton.bounds.size.width/2, y: tvButton.bounds.size.height/2) + } } }, completion:nil) }