SwipeTransition allows trendy transitions using swipe gesture such as "swipe back".
Just setting these frameworks in the Linked Frameworks and Libraries
, it works. (if you use Carthage)
Notes: these frameworks use Method Swizzling.
When setting manually without Method Swizzling, please use SwipeTransition.framework
only.
- Swipe back anywhere.
- Swipe to dismiss anywhere.
- Apply to all view controllers automatically!
- Xcode 9.x
- Swift 4.x
- iOS 8.0+
github "tattn/SwipeTransition"
pod "SwipeTransition"
pod "SwipeTransitionAutoSwipeBack" # if needed
pod "SwipeTransitionAutoSwipeToDismiss" # if needed
It is possible to disable the feature only for a specific view controller.
class NoSwipeVC: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
navigationController?.swipeBack?.isEnabled = false
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
navigationController?.swipeBack?.isEnabled = true
}
}
Notes: when you use AutoSwipeBack.framework
, these are unnecessary.
Just use SwipeBackNavigationController
instead of UINavigationController
. Of course, you can set it with Interface Builder.
let viewController = UIViewController()
let navigationController = SwipeBackNavigationController(rootViewControlelr: viewController)
Another way is to set swipeBack
.
class CustomNavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
swipeBack = SwipeBackController(navigationController: self)
}
}
It is possible to disable the feature only for a specific view controller.
class NoSwipeVC: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
navigationController?.swipeToDismiss?.isEnabled = false
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
navigationController?.swipeToDismiss?.isEnabled = true
}
}
It also works on scroll view.
class ScrollVC: UIViewController, UIScrollViewDelegate {
@IBOutlet private var scrollView: UIScrollView!
override func viewDidLoad() {
super.viewDidLoad()
scrollView.delegate = self
swipeToDismiss?.setScrollViews([scrollView])
// in case of presenting a navigationController
// navigationController?.swipeToDismiss?.setScrollViews([scrollView])
}
}
Notes: when you use AutoSwipeToDismiss.framework
, these are unnecessary.
Just use SwipeToDismissNavigationController
instead of UINavigationController
. Of course, you can set it with Interface Builder.
let viewController = UIViewController()
let navigationController = SwipeToDismissNavigationController(rootViewControlelr: viewController)
Another way is to set swipeToDismiss
.
class CustomNavigationController: UINavigationController {
override func viewDidLoad() {
super.viewDidLoad()
modalPresentationStyle = .overFullScreen
swipeToDismiss = SwipeToDismissController(viewController: self)
}
}
You can also change the behavior such as animation.
SwipeBackConfiguration.shared.parallaxFactor = 0.6
SwipeToDismissConfiguration.shared.dismissHeightRatio = 0.5
Inheriting the configure class, you can set it with computed property.
class CustomSwipeBackConfiguration: SwipeBackConfiguration {
override var transitionDuration: TimeInterval {
get { return 1.5 }
set { super.transitionDuration = newValue }
}
}
SwipeBackConfiguration.shared = CustomSwipeBackConfiguration()
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
SwipeTransition is released under the MIT license. See LICENSE for details.