From 330a75c296138bbdeb8751f5dc73b92b7313b22f Mon Sep 17 00:00:00 2001 From: SatoshiN21 Date: Thu, 1 Sep 2016 15:55:24 +0900 Subject: [PATCH 01/18] add force option to manually swipe function --- Pod/Classes/KolodaView/KolodaView.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Pod/Classes/KolodaView/KolodaView.swift b/Pod/Classes/KolodaView/KolodaView.swift index 3a816ac8..6991cbfb 100644 --- a/Pod/Classes/KolodaView/KolodaView.swift +++ b/Pod/Classes/KolodaView/KolodaView.swift @@ -518,7 +518,12 @@ public class KolodaView: UIView, DraggableCardDelegate { } } - public func swipe(direction: SwipeResultDirection) { + public func swipe(direction: SwipeResultDirection,force: Bool = true) { + + let shouldSwipe = delegate?.koloda(self, shouldSwipeCardAtIndex: UInt(self.currentCardIndex), inDirection: direction) ?? true + guard force || shouldSwipe else { + return + } let validDirection = delegate?.koloda(self, allowedDirectionsForIndex: UInt(currentCardIndex)).contains(direction) ?? true guard validDirection else { return } From bc7df57405de366db5ec2aaf7de5f355e83c0b6f Mon Sep 17 00:00:00 2001 From: Ed Baev Date: Thu, 1 Sep 2016 18:02:50 +0300 Subject: [PATCH 02/18] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index ebcf6d5a..019cb646 100644 --- a/README.md +++ b/README.md @@ -279,6 +279,7 @@ Version 1.0 ![Preview](https://github.com/Yalantis/Koloda/blob/master/Example/UsageExamples/bro.gif) - [Storage Space Plus](https://itunes.apple.com/us/app/storage-space-plus-compress/id1086277462?mt=8). +- [Color Dating](https://itunes.apple.com/us/app/color-dating-free-app-for/id1100827439?mt=8). #### Let us know! From ee29ddd92e89f2256c51eac5c351a5d602c7b614 Mon Sep 17 00:00:00 2001 From: SatoshiN21 Date: Tue, 6 Sep 2016 14:38:25 +0900 Subject: [PATCH 03/18] set alpha value compulsorily (fix #201) --- Pod/Classes/KolodaView/KolodaViewAnimatior.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Pod/Classes/KolodaView/KolodaViewAnimatior.swift b/Pod/Classes/KolodaView/KolodaViewAnimatior.swift index c3b512fb..4d97e7ff 100644 --- a/Pod/Classes/KolodaView/KolodaViewAnimatior.swift +++ b/Pod/Classes/KolodaView/KolodaViewAnimatior.swift @@ -50,6 +50,7 @@ public class KolodaViewAnimator { firstCardAppearAnimation.duration = 1.0 firstCardAppearAnimation.completionBlock = { _, finished in completion?(finished) + card.alpha = 1.0 } card.pop_addAnimation(firstCardAppearAnimation, forKey: "reverseCardAlphaAnimation") From dac6c3d1bc15a9d44dae65b08269c3ca874ba1dc Mon Sep 17 00:00:00 2001 From: Serhii Butenko Date: Wed, 28 Sep 2016 15:19:48 +0300 Subject: [PATCH 04/18] Create ISSUE_TEMPLATE.md --- .github/ISSUE_TEMPLATE.md | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE.md diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 00000000..add69cd9 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,42 @@ +# Report + +> The more information you provide, the faster we can help you. + +⚠️ Select what you want - **a feature request** or **report a bug**. Please remove the section you aren't interested in. + +## A feature request + +### What do you do? + +> Please describe what you want to add to the component. + +### How should it look like? + +> Please add images. + +## Report a bug + +### What did you do? + +> Please replace this with what you did. + +### What did you expect to happen? + +> Please replace this with what you expected to happen. + +### What happened instead? + +> Please replace this with what happened instead. + +### Your Environment + +- [ ] Version of the component: _insert here_ +- [ ] Swift version: _insert here_ +- [ ] Xcode version: _insert here_ +- [ ] macOS version: _insert here_ +- [ ] If you use Cocoapods: _run `pod env | pbcopy` and insert here_ +- [ ] If you use Carthage: _run `carthage version | pbcopy` and insert here_ + +### Project that demonstrates the bug + +> Please add a link to a project we can download that reproduces the bug. From ed0e2b9e3f0f1f261c9700cc79d1f292b26bd16c Mon Sep 17 00:00:00 2001 From: Serhii Butenko Date: Wed, 28 Sep 2016 15:24:43 +0300 Subject: [PATCH 05/18] Update ISSUE_TEMPLATE.md --- .github/ISSUE_TEMPLATE.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index add69cd9..04ad2a6e 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -6,7 +6,7 @@ ## A feature request -### What do you do? +### What do you want to add? > Please describe what you want to add to the component. @@ -32,8 +32,9 @@ - [ ] Version of the component: _insert here_ - [ ] Swift version: _insert here_ +- [ ] iOS version: _insert here_ +- [ ] Device: _insert here_ - [ ] Xcode version: _insert here_ -- [ ] macOS version: _insert here_ - [ ] If you use Cocoapods: _run `pod env | pbcopy` and insert here_ - [ ] If you use Carthage: _run `carthage version | pbcopy` and insert here_ From 6a1868bae760a2d468557f0373046260dc42b065 Mon Sep 17 00:00:00 2001 From: Serhii Butenko Date: Thu, 1 Dec 2016 15:04:15 +0200 Subject: [PATCH 06/18] Update LICENSE --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 01ace4b9..64e2a295 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 Yalantis +Copyright (c) 2016 Yalantis Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 5a1218110412cb1a8af36eee927a925e1f687d3e Mon Sep 17 00:00:00 2001 From: Serhii Butenko Date: Thu, 1 Dec 2016 15:04:34 +0200 Subject: [PATCH 07/18] Update ISSUE_TEMPLATE.md --- .github/ISSUE_TEMPLATE.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 04ad2a6e..5449bc82 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -30,13 +30,13 @@ ### Your Environment -- [ ] Version of the component: _insert here_ -- [ ] Swift version: _insert here_ -- [ ] iOS version: _insert here_ -- [ ] Device: _insert here_ -- [ ] Xcode version: _insert here_ -- [ ] If you use Cocoapods: _run `pod env | pbcopy` and insert here_ -- [ ] If you use Carthage: _run `carthage version | pbcopy` and insert here_ +- Version of the component: _insert here_ +- Swift version: _insert here_ +- iOS version: _insert here_ +- Device: _insert here_ +- Xcode version: _insert here_ +- If you use Cocoapods: _run `pod env | pbcopy` and insert here_ +- If you use Carthage: _run `carthage version | pbcopy` and insert here_ ### Project that demonstrates the bug From 57b0655808e7b5fba7e629da786e5d2ca6b81d63 Mon Sep 17 00:00:00 2001 From: Roman Kyrylenko Date: Thu, 22 Dec 2016 12:48:50 +0200 Subject: [PATCH 08/18] removed run script build phase for carthage (fixes #243) --- Koloda.xcodeproj/project.pbxproj | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/Koloda.xcodeproj/project.pbxproj b/Koloda.xcodeproj/project.pbxproj index 8526cd75..7f2dd657 100644 --- a/Koloda.xcodeproj/project.pbxproj +++ b/Koloda.xcodeproj/project.pbxproj @@ -144,7 +144,6 @@ C517E4A71D9CF9010002D88F /* Frameworks */, C517E4A81D9CF9010002D88F /* Headers */, C517E4A91D9CF9010002D88F /* Resources */, - C517E4F61D9D01120002D88F /* Carthage */, ); buildRules = ( ); @@ -197,24 +196,6 @@ }; /* End PBXResourcesBuildPhase section */ -/* Begin PBXShellScriptBuildPhase section */ - C517E4F61D9D01120002D88F /* Carthage */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - "$(SRCROOT)/Carthage/Build/iOS/pop.framework", - ); - name = Carthage; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "/usr/local/bin/carthage copy-frameworks"; - }; -/* End PBXShellScriptBuildPhase section */ - /* Begin PBXSourcesBuildPhase section */ C517E4A61D9CF9010002D88F /* Sources */ = { isa = PBXSourcesBuildPhase; From c48ec08afab4f77bbd76d3b2c0bd0ce0e801a33f Mon Sep 17 00:00:00 2001 From: Roman Kyrylenko Date: Thu, 22 Dec 2016 13:02:40 +0200 Subject: [PATCH 09/18] removed framework from copy phase; --- Koloda.xcodeproj/project.pbxproj | 2 -- 1 file changed, 2 deletions(-) diff --git a/Koloda.xcodeproj/project.pbxproj b/Koloda.xcodeproj/project.pbxproj index 7f2dd657..69eda9da 100644 --- a/Koloda.xcodeproj/project.pbxproj +++ b/Koloda.xcodeproj/project.pbxproj @@ -14,7 +14,6 @@ C517E4F21D9D00520002D88F /* KolodaViewAnimatior.swift in Sources */ = {isa = PBXBuildFile; fileRef = C517E4E81D9D00520002D88F /* KolodaViewAnimatior.swift */; }; C517E4F31D9D00520002D88F /* OverlayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C517E4EA1D9D00520002D88F /* OverlayView.swift */; }; C517E4F41D9D00520002D88F /* SwipeResultDirection.swift in Sources */ = {isa = PBXBuildFile; fileRef = C517E4EB1D9D00520002D88F /* SwipeResultDirection.swift */; }; - C517E4F91D9D01920002D88F /* pop.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C517E4F81D9D01920002D88F /* pop.framework */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -35,7 +34,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - C517E4F91D9D01920002D88F /* pop.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; From 4ae54712e282753a35ee25ab2d9f11da4eab3266 Mon Sep 17 00:00:00 2001 From: Roman Kyrylenko Date: Thu, 22 Dec 2016 13:37:19 +0200 Subject: [PATCH 10/18] updated readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 019cb646..d93b2b76 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -KolodaView [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) ![Swift 2.2.x](https://img.shields.io/badge/Swift-2.2.x-orange.svg) +KolodaView [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) ![Swift 3.0.x](https://img.shields.io/badge/Swift-3.0.x-orange.svg) -------------- [![Yalantis](https://raw.githubusercontent.com/Yalantis/PullToMakeSoup/master/PullToMakeSoupDemo/Resouces/badge_dark.png)](https://Yalantis.com/?utm_source=github) From 4a9ebf2a1a88fdece2dc6a1239f151d046ece5fe Mon Sep 17 00:00:00 2001 From: Serhii Butenko Date: Fri, 23 Dec 2016 08:46:32 +0200 Subject: [PATCH 11/18] Update README.md --- README.md | 57 +++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index d93b2b76..ace0df6f 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ KolodaView requires ARC. ------------------ ```ruby -pod 'Koloda', '~> 3.1.2' +pod 'Koloda', '~> 4.0' ``` Thread Safety @@ -38,18 +38,12 @@ KolodaView is subclassed from UIView and - as with all UIKit components - it sho Installation -------------- -To install via CocoaPods add this lines to your Podfile +To install via CocoaPods add this lines to your Podfile. You need CocoaPods v. 1.1 or higher ```ruby use_frameworks! pod "Koloda" ``` -Note: Due to [CocoaPods/CocoaPods#4420 issue](https://github.com/CocoaPods/CocoaPods/issues/4420) there is problem with compiling project with Xcode 7.1 and CocoaPods v0.39.0. However there is a temporary workaround for this: -Add next lines to the end of your Podfile -```ruby -post_install do |installer| -`find Pods -regex 'Pods/pop.*\\.h' -print0 | xargs -0 sed -i '' 's/\\(<\\)pop\\/\\(.*\\)\\(>\\)/\\"\\2\\"/'` -end -``` + To install via Carthage add this lines to your Cartfile ```ruby github "Yalantis/Koloda" @@ -84,8 +78,8 @@ To install manually the KolodaView class in an app, just drag the KolodaView, Dr dataSource.reset() } - func koloda(koloda: KolodaView, didSelectCardAtIndex index: UInt) { - UIApplication.sharedApplication().openURL(NSURL(string: "http://yalantis.com/")!) + func koloda(koloda: KolodaView, didSelectCardAt index: Int) { + UIApplication.sharedApplication().openURL(NSURL(string: "https://yalantis.com/")!) } } ``` @@ -93,15 +87,15 @@ To install manually the KolodaView class in an app, just drag the KolodaView, Dr ```swift extension MyKolodaViewController: KolodaViewDataSource { - func kolodaNumberOfCards(koloda:KolodaView) -> UInt { + func kolodaNumberOfCards(koloda:KolodaView) -> Int { return images.count } - func koloda(koloda: KolodaView, viewForCardAtIndex index: UInt) -> UIView { - return UIImageView(image: images[Int(index)]) + func koloda(koloda: KolodaView, viewForCardAt index: Int) -> UIView { + return UIImageView(image: images[index]) } - func koloda(koloda: KolodaView, viewForCardOverlayAtIndex index: UInt) -> OverlayView? { + func koloda(koloda: KolodaView, viewForCardOverlayAt index: Int) -> OverlayView? { return NSBundle.mainBundle().loadNibNamed("OverlayView", owner: self, options: nil)[0] as? OverlayView } @@ -158,16 +152,16 @@ func applyAppearAnimation() ``` Applies appear animation. ```swift -func swipe(.Left) +func swipe(.left) ``` Applies swipe left animation and action, increment currentCardNumber. ```swift -func swipe(.Right) +func swipe(.right) ``` Applies swipe right animation and action, increment currentCardNumber. ```swift -public func frameForCardAtIndex(index: UInt) -> CGRect +public func frameForCardAtIndex(index: Int) -> CGRect ``` Calculates frames for cards. Useful for overriding. See example to learn more about it. @@ -176,30 +170,30 @@ Protocols The KolodaView follows the Apple convention for data-driven views by providing two protocol interfaces, KolodaViewDataSource and KolodaViewDelegate. The KolodaViewDataSource protocol has the following methods: ```swift -func koloda(kolodaNumberOfCards koloda: KolodaView) -> UInt +func koloda(kolodaNumberOfCards koloda: KolodaView) -> Int ``` Return the number of items (views) in the KolodaView. ```swift -func koloda(koloda: KolodaView, viewForCardAtIndex index: UInt) -> UIView +func koloda(koloda: KolodaView, viewForCardAt index: Int) -> UIView ``` Return a view to be displayed at the specified index in the KolodaView. ```swift -func koloda(koloda: KolodaView, viewForCardOverlayAtIndex index: UInt) -> OverlayView? +func koloda(koloda: KolodaView, viewForCardOverlayAt index: Int) -> OverlayView? ``` Return a view for card overlay at the specified index. For setting custom overlay action on swiping(left/right), you should override didSet of overlayState property in OverlayView. (See Example) The KolodaViewDelegate protocol has the following methods: ```swift -func koloda(koloda: KolodaView, allowedDirectionsForIndex index: UInt) -> [SwipeResultDirection] +func koloda(koloda: KolodaView, allowedDirectionsForIndex index: Int) -> [SwipeResultDirection] ``` -Return the allowed directions for a given card, defaults to `[.Left, .Right]` +Return the allowed directions for a given card, defaults to `[.left, .right]` ```swift -func koloda(koloda: KolodaView, shouldSwipeCardAtIndex index: UInt, inDirection direction: SwipeResultDirection) -> Bool +func koloda(koloda: KolodaView, shouldSwipeCardAt index: Int, in direction: SwipeResultDirection) -> Bool ``` This method is called before the KolodaView swipes card. Return `true` or `false` to allow or deny the swipe. ```swift -func koloda(koloda: KolodaView, didSwipeCardAtIndex index: UInt, inDirection direction: SwipeResultDirection) +func koloda(koloda: KolodaView, didSwipeCardAt index: Int, in direction: SwipeResultDirection) ``` This method is called whenever the KolodaView swipes card. It is called regardless of whether the card was swiped programatically or through user interaction. ```swift @@ -207,7 +201,7 @@ func kolodaDidRunOutOfCards(koloda: KolodaView) ``` This method is called when the KolodaView has no cards to display. ```swift -func koloda(koloda: KolodaView, didSelectCardAtIndex index: UInt) +func koloda(koloda: KolodaView, didSelectCardAt index: Int) ``` This method is called when one of cards is tapped. ```swift @@ -223,7 +217,7 @@ func kolodaShouldTransparentizeNextCard(koloda: KolodaView) -> Bool ``` This method is fired on koloda's layout and after swiping. If you return YES from the method or don't implement it, the koloda will transparentize next card below front card. ```swift -func koloda(koloda: KolodaView, draggedCardWithPercentage finishPercentage: CGFloat, inDirection direction: SwipeResultDirection) +func koloda(koloda: KolodaView, draggedCardWithPercentage finishPercentage: CGFloat, in direction: SwipeResultDirection) ``` This method is called whenever the KolodaView recognizes card dragging event. ```swift @@ -235,11 +229,11 @@ func kolodaDidResetCard(koloda: KolodaView) ``` This method is fired after resetting the card. ```swift -func koloda(koloda: KolodaView, didShowCardAtIndex index: UInt) +func koloda(koloda: KolodaView, didShowCardAt index: Int) ``` This method is called after a card has been shown, after animation is complete ```swift -func koloda(koloda: KolodaView, shouldDragCardAtIndex index: UInt ) -> Bool +func koloda(koloda: KolodaView, shouldDragCardAt index: Int) -> Bool ``` This method is called when the card is beginning to be dragged. If you return YES from the method or don't implement it, the card will move in the direction of the drag. If you return NO the card will @@ -248,6 +242,11 @@ not move. Release Notes ---------------- +Version 4.0 +- Swift 3 support +- Get rid of UInt +- Common bugfix + Version 3.1 - Multiple Direction Support From 90062c46ab736f92a468d4640e5d74f00eca4245 Mon Sep 17 00:00:00 2001 From: Boris Vinogradov Date: Fri, 13 Jan 2017 12:35:40 +0200 Subject: [PATCH 12/18] Update LICENSE --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 64e2a295..f10f992c 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2016 Yalantis +Copyright (c) 2017 Yalantis Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 674f0cf4357aa8cd5fa9f402ebf4a0d773dd93ab Mon Sep 17 00:00:00 2001 From: Boris Vinogradov Date: Fri, 13 Jan 2017 12:39:50 +0200 Subject: [PATCH 13/18] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ace0df6f..cb10f970 100644 --- a/README.md +++ b/README.md @@ -292,7 +292,7 @@ License The MIT License (MIT) -Copyright © 2016 Yalantis +Copyright © 2017 Yalantis 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: From a8150de4e379a682249dbd738f66a13630f99c26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Benaiteau?= Date: Wed, 1 Mar 2017 12:30:40 +0700 Subject: [PATCH 14/18] Add delegate to control alpha of card depending on index --- Pod/Classes/KolodaView/KolodaView.swift | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Pod/Classes/KolodaView/KolodaView.swift b/Pod/Classes/KolodaView/KolodaView.swift index 3a816ac8..f5708e5b 100644 --- a/Pod/Classes/KolodaView/KolodaView.swift +++ b/Pod/Classes/KolodaView/KolodaView.swift @@ -47,6 +47,7 @@ public protocol KolodaViewDelegate:class { func kolodaShouldApplyAppearAnimation(koloda: KolodaView) -> Bool func kolodaShouldMoveBackgroundCard(koloda: KolodaView) -> Bool func kolodaShouldTransparentizeNextCard(koloda: KolodaView) -> Bool +func kolodaOpacityForNextCard(koloda: KolodaView, at index: UInt) -> CGFloat func koloda(koloda: KolodaView, draggedCardWithPercentage finishPercentage: CGFloat, inDirection direction: SwipeResultDirection) func kolodaDidResetCard(koloda: KolodaView) func kolodaSwipeThresholdRatioMargin(koloda: KolodaView) -> CGFloat? @@ -65,6 +66,7 @@ public extension KolodaViewDelegate { func kolodaShouldApplyAppearAnimation(koloda: KolodaView) -> Bool { return true } func kolodaShouldMoveBackgroundCard(koloda: KolodaView) -> Bool { return true } func kolodaShouldTransparentizeNextCard(koloda: KolodaView) -> Bool { return true } + func kolodaOpacityForNextCard(koloda: KolodaView, at index: Int) -> CGFloat { return defaultAlphaValueSemiTransparent } func koloda(koloda: KolodaView, draggedCardWithPercentage finishPercentage: CGFloat, inDirection direction: SwipeResultDirection) {} func kolodaDidResetCard(koloda: KolodaView) {} func kolodaSwipeThresholdRatioMargin(koloda: KolodaView) -> CGFloat? { return nil} @@ -128,7 +130,7 @@ public class KolodaView: UIView, DraggableCardDelegate { nextCardView.userInteractionEnabled = isTop nextCardView.alpha = alphaValueOpaque if shouldTransparentizeNextCard && !isTop { - nextCardView.alpha = alphaValueSemiTransparent + nextCardView.alpha = self.cardAlphaTransparent(at: index) } visibleCards.append(nextCardView) isTop ? addSubview(nextCardView) : insertSubview(nextCardView, belowSubview: visibleCards[index - 1]) @@ -219,7 +221,7 @@ public class KolodaView: UIView, DraggableCardDelegate { //For fully visible next card, when moving top card if shouldTransparentizeNextCard { if index == 1 { - card.alpha = alphaValueSemiTransparent + (alphaValueOpaque - alphaValueSemiTransparent) * fraction + card.alpha = alphaValueSemiTransparent + (alphaValueOpaque - self.cardAlphaTransparent(at: index)) * fraction } } } @@ -282,7 +284,7 @@ public class KolodaView: UIView, DraggableCardDelegate { for index in 1..<_self.visibleCards.count { let card = _self.visibleCards[index] if _self.shouldTransparentizeNextCard { - card.alpha = index == 0 ? _self.alphaValueOpaque : _self.alphaValueSemiTransparent + card.alpha = index == 0 ? _self.alphaValueOpaque : _self.cardAlphaTransparent(at: index) } } } @@ -322,6 +324,13 @@ public class KolodaView: UIView, DraggableCardDelegate { visibleCards.removeAll(keepCapacity: true) } + private func cardAlphaTransparent(at index: Int) -> CGFloat { + + let alphaTransparent: CGFloat = self.delegate != nil ? self.delegate!.kolodaOpacityForNextCard(self, at: UInt(index)) : alphaValueSemiTransparent + return alphaTransparent + } + + //MARK: Actions private func swipedAction(direction: SwipeResultDirection) { animating = true @@ -381,7 +390,8 @@ public class KolodaView: UIView, DraggableCardDelegate { var animationCompletion: ((Bool) -> Void)? = nil if index != 0 { if shouldTransparentizeNextCard { - currentCard.alpha = alphaValueSemiTransparent + let alphaTransparent: CGFloat = delegate != nil ? delegate!.kolodaOpacityForNextCard(self, at: index) : alphaValueSemiTransparent + currentCard.alpha = alphaTransparent } } else { animationCompletion = { finished in @@ -440,7 +450,8 @@ public class KolodaView: UIView, DraggableCardDelegate { for (index, card) in visibleCards.dropFirst().enumerate() { if shouldTransparentizeNextCard { - card.alpha = alphaValueSemiTransparent + let alphaTransparent: CGFloat = delegate != nil ? delegate!.kolodaOpacityForNextCard(self, at: index) : alphaValueSemiTransparent + card.alpha = alphaTransparent } card.userInteractionEnabled = false @@ -465,7 +476,8 @@ public class KolodaView: UIView, DraggableCardDelegate { for index in startIndex...endIndex { let nextCardView = generateCard(frameForTopCard()) layoutCard(nextCardView, atIndex: UInt(index)) - nextCardView.alpha = shouldTransparentizeNextCard ? alphaValueSemiTransparent : alphaValueOpaque + let alphaTransparent: CGFloat = delegate != nil ? delegate!.kolodaOpacityForNextCard(self, at: index) : alphaValueSemiTransparent + nextCardView.alpha = shouldTransparentizeNextCard ? alphaTransparent : alphaValueOpaque visibleCards.append(nextCardView) configureCard(nextCardView, atIndex: UInt(currentCardIndex + index)) From 83ac9f1599cc0c1d3311599d7f79bc87550fbaab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Benaiteau?= Date: Wed, 1 Mar 2017 15:30:37 +0700 Subject: [PATCH 15/18] Consider animated flag in removeCardInIndexRange --- Pod/Classes/KolodaView/KolodaView.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Pod/Classes/KolodaView/KolodaView.swift b/Pod/Classes/KolodaView/KolodaView.swift index f5708e5b..84e3b55a 100644 --- a/Pod/Classes/KolodaView/KolodaView.swift +++ b/Pod/Classes/KolodaView/KolodaView.swift @@ -646,13 +646,17 @@ public class KolodaView: UIView, DraggableCardDelegate { // MARK: Cards managing - Deletion - private func proceedDeletionInRange(range: Range) { + private func proceedDeletionInRange(range: Range, animated: Bool) { let deletionIndexes = [Int](range) deletionIndexes.sort { $0 > $1 }.forEach { deletionIndex in let visibleCardIndex = deletionIndex - currentCardIndex let card = visibleCards[visibleCardIndex] card.delegate = nil - card.swipe(.Right) + if animated { + card.swipe(.Right) + } else { + card.removeFromSuperview() + } visibleCards.removeAtIndex(visibleCardIndex) } } @@ -667,7 +671,7 @@ public class KolodaView: UIView, DraggableCardDelegate { countOfCards = Int(dataSource.kolodaNumberOfCards(self)) let visibleIndexes = [Int](indexRange).filter { $0 >= currentCardIndex && $0 < currentCardIndex + countOfVisibleCards } if !visibleIndexes.isEmpty { - proceedDeletionInRange(visibleIndexes[0]...visibleIndexes[visibleIndexes.count - 1]) + proceedDeletionInRange(visibleIndexes[0]...visibleIndexes[visibleIndexes.count - 1], animated: animated) } currentCardIndex -= Array(indexRange).filter { $0 < currentCardIndex }.count loadMissingCards(missingCardsCount()) From 19aa1cdd2a9a7375ff4ba33ed72b5e8ed8007699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Benaiteau?= Date: Wed, 1 Mar 2017 15:41:07 +0700 Subject: [PATCH 16/18] Make default swipe right animation for remove card changeable --- Pod/Classes/KolodaView/KolodaView.swift | 2 +- Pod/Classes/KolodaView/KolodaViewAnimatior.swift | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Pod/Classes/KolodaView/KolodaView.swift b/Pod/Classes/KolodaView/KolodaView.swift index 84e3b55a..950e2255 100644 --- a/Pod/Classes/KolodaView/KolodaView.swift +++ b/Pod/Classes/KolodaView/KolodaView.swift @@ -653,7 +653,7 @@ public class KolodaView: UIView, DraggableCardDelegate { let card = visibleCards[visibleCardIndex] card.delegate = nil if animated { - card.swipe(.Right) + animator.removeCardAnimation(card) } else { card.removeFromSuperview() } diff --git a/Pod/Classes/KolodaView/KolodaViewAnimatior.swift b/Pod/Classes/KolodaView/KolodaViewAnimatior.swift index c3b512fb..6c98c6ac 100644 --- a/Pod/Classes/KolodaView/KolodaViewAnimatior.swift +++ b/Pod/Classes/KolodaView/KolodaViewAnimatior.swift @@ -107,6 +107,12 @@ public class KolodaViewAnimator { ) } + public func removeCardAnimation(card: DraggableCardView, completion: AnimationCompletionBlock = nil) { + card.swipe(.Right) + completion?(true) + } + + internal func resetBackgroundCardsWithCompletion(completion: AnimationCompletionBlock = nil) { UIView.animateWithDuration( 0.2, From 0b5ef378eb8dc8716832d915b2bd5c3e0d503f6f Mon Sep 17 00:00:00 2001 From: Vitaly Date: Fri, 14 Oct 2016 20:32:25 +0300 Subject: [PATCH 17/18] Control appear animation duration --- Pod/Classes/KolodaView/KolodaView.swift | 7 +++++-- Pod/Classes/KolodaView/KolodaViewAnimatior.swift | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Pod/Classes/KolodaView/KolodaView.swift b/Pod/Classes/KolodaView/KolodaView.swift index 950e2255..bda27823 100644 --- a/Pod/Classes/KolodaView/KolodaView.swift +++ b/Pod/Classes/KolodaView/KolodaView.swift @@ -15,6 +15,7 @@ private let defaultBackgroundCardsTopMargin: CGFloat = 4.0 private let defaultBackgroundCardsScalePercent: CGFloat = 0.95 private let defaultBackgroundCardsLeftMargin: CGFloat = 8.0 private let defaultBackgroundCardFrameAnimationDuration: NSTimeInterval = 0.2 +private let defaultAppearanceAnimationDuration: NSTimeInterval = 0.8 //Opacity values private let defaultAlphaValueOpaque: CGFloat = 1.0 @@ -83,6 +84,8 @@ public class KolodaView: UIView, DraggableCardDelegate { public var alphaValueSemiTransparent = defaultAlphaValueSemiTransparent public var shouldPassthroughTapsWhenNoVisibleCards = false + public var appearanceAnimationDuration = defaultAppearanceAnimationDuration + public weak var dataSource: KolodaViewDataSource? { didSet { setupDeck() @@ -235,10 +238,10 @@ public class KolodaView: UIView, DraggableCardDelegate { userInteractionEnabled = false animating = true - animator.animateAppearanceWithCompletion { [weak self] _ in + animator.animateAppearance(appearanceAnimationDuration, completion: { [weak self] _ in self?.userInteractionEnabled = true self?.animating = false - } + }) } public func applyAppearAnimationIfNeeded() { diff --git a/Pod/Classes/KolodaView/KolodaViewAnimatior.swift b/Pod/Classes/KolodaView/KolodaViewAnimatior.swift index 6c98c6ac..e7729a63 100644 --- a/Pod/Classes/KolodaView/KolodaViewAnimatior.swift +++ b/Pod/Classes/KolodaView/KolodaViewAnimatior.swift @@ -20,11 +20,11 @@ public class KolodaViewAnimator { self.koloda = koloda } - public func animateAppearanceWithCompletion(completion: AnimationCompletionBlock = nil) { + public func animateAppearance(duration: NSTimeInterval, completion: AnimationCompletionBlock = nil) { let kolodaAppearScaleAnimation = POPBasicAnimation(propertyNamed: kPOPLayerScaleXY) kolodaAppearScaleAnimation.beginTime = CACurrentMediaTime() + cardSwipeActionAnimationDuration - kolodaAppearScaleAnimation.duration = 0.8 + kolodaAppearScaleAnimation.duration = duration kolodaAppearScaleAnimation.fromValue = NSValue(CGPoint: CGPoint(x: 0.1, y: 0.1)) kolodaAppearScaleAnimation.toValue = NSValue(CGPoint: CGPoint(x: 1.0, y: 1.0)) kolodaAppearScaleAnimation.completionBlock = { (_, finished) in @@ -36,7 +36,7 @@ public class KolodaViewAnimator { kolodaAppearAlphaAnimation.beginTime = CACurrentMediaTime() + cardSwipeActionAnimationDuration kolodaAppearAlphaAnimation.fromValue = NSNumber(float: 0.0) kolodaAppearAlphaAnimation.toValue = NSNumber(float: 1.0) - kolodaAppearAlphaAnimation.duration = 0.8 + kolodaAppearAlphaAnimation.duration = duration koloda?.pop_addAnimation(kolodaAppearAlphaAnimation, forKey: "kolodaAppearScaleAnimation") koloda?.layer.pop_addAnimation(kolodaAppearScaleAnimation, forKey: "kolodaAppearAlphaAnimation") From 72706c538a33cc9b2652ffe412c570923282b0bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Benaiteau?= Date: Tue, 21 Mar 2017 16:48:27 +0800 Subject: [PATCH 18/18] Fixes transparency for visible cards on swipe --- Pod/Classes/KolodaView/KolodaView.swift | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Pod/Classes/KolodaView/KolodaView.swift b/Pod/Classes/KolodaView/KolodaView.swift index bda27823..60279b65 100644 --- a/Pod/Classes/KolodaView/KolodaView.swift +++ b/Pod/Classes/KolodaView/KolodaView.swift @@ -393,8 +393,7 @@ public class KolodaView: UIView, DraggableCardDelegate { var animationCompletion: ((Bool) -> Void)? = nil if index != 0 { if shouldTransparentizeNextCard { - let alphaTransparent: CGFloat = delegate != nil ? delegate!.kolodaOpacityForNextCard(self, at: index) : alphaValueSemiTransparent - currentCard.alpha = alphaTransparent + currentCard.alpha = cardAlphaTransparent(at: index) } } else { animationCompletion = { finished in @@ -453,8 +452,7 @@ public class KolodaView: UIView, DraggableCardDelegate { for (index, card) in visibleCards.dropFirst().enumerate() { if shouldTransparentizeNextCard { - let alphaTransparent: CGFloat = delegate != nil ? delegate!.kolodaOpacityForNextCard(self, at: index) : alphaValueSemiTransparent - card.alpha = alphaTransparent + card.alpha = cardAlphaTransparent(at: index) } card.userInteractionEnabled = false @@ -543,8 +541,11 @@ public class KolodaView: UIView, DraggableCardDelegate { animating = true if visibleCards.count > 1 { - let nextCard = visibleCards[1] - nextCard.alpha = shouldTransparentizeNextCard ? alphaValueSemiTransparent : alphaValueOpaque + for i in 1..