Dimitri James Tsiflitzis
CocoaheadsSKG
for the rest of us
CocoaHeads is a group devoted to the discussion of Swift, Objective-C and Cocoa. During meetings, members present on their projects, offer tutorials and discuss the latest news over a drink or two.
Website (http://cocoaheads.gr/)
Slides (https://speakerdeck.com/cocoaheadsskg)
Videos (https://www.youtube.com/channel/UCo7SSmiSt0R9ab1beWsX4ZA)
Twitter (https://twitter.com/cocoaheadsskg)
Meetup (https://www.meetup.com/CocoaHeadsSKG/)
CocoaheadsSKG
CocoaheadsSKG
CocoaheadsSKG
...and bringing a user interface to life.
CocoaheadsSKG
I could have been somebody
I'm Dimitri
I could have been a contender
Instead I'm just a simple man trying to make my way in the universe
CocoaheadsSKG
To connect multiple steps in a series
CocoaheadsSKG
Presenting a view controller
CocoaheadsSKG
let viewController = ...
present(viewController, animated: true)Code for presenting a view controller
CocoaheadsSKG
Pushing a view controller onto the navigation stack
CocoaheadsSKG
let vc = ...
navigationController?.pushViewController(vc, animated: true)
Code for pushing
CocoaheadsSKG
To create custom transitions you have to follow three steps:
CocoaheadsSKG
CocoaheadsSKG
UIViewControllerTransitioningDelegate
CocoaheadsSKG
These objects are returned by the transition delegate, so you can implement your own desired custom view animations.
UIViewControllerAnimatedTransitioning
CocoaheadsSKG
UIViewControllerContextTransitioning
CocoaheadsSKG
This gives you the "magical" ability to swipe a navigation controller interactively back and forth from the edge of the 📱
UIPercentDrivenInteractiveTransition
CocoaheadsSKG
CocoaheadsSKG
CocoaheadsSKG
CocoaheadsSKG
CocoaheadsSKG
CocoaheadsSKG
CocoaheadsSKG
CocoaheadsSKG
class DetailViewController: UIViewController {
/* ... */
override func prepare(for segue: UIStoryboardSegue,
sender: Any?) {
super.prepare(for: segue, sender: sender)
guard
let controller = segue.destination as? ModalViewController
else {
return
}
controller.transitioningDelegate = self
}
}
CocoaheadsSKG
extension DetailViewController: UIViewControllerTransitioningDelegate {
func animationController(forPresented presented: UIViewController,
presenting: UIViewController,
source: UIViewController)
-> UIViewControllerAnimatedTransitioning? {
return FadePushAnimator()
}
func animationController(forDismissed dismissed: UIViewController)
-> UIViewControllerAnimatedTransitioning? {
return FadePopAnimator()
}
}
CocoaheadsSKG
open class FadeOutAnimator: NSObject, UIViewControllerAnimatedTransitioning {
let duration: TimeInterval
public init(type: TransitionType, duration: TimeInterval = 0.25) {
self.duration = duration
super.init()
}
open func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?)
-> TimeInterval {
return self.duration
}
open override func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
guard
let fromViewController = transitionContext.viewController(forKey: .from)
else {
return
}
let duration = self.transitionDuration(using: transitionContext)
UIView.animate(withDuration: duration, animations: {
fromViewController.view.alpha = 0
}, completion: { _ in
transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
})
}
}CocoaheadsSKG
CocoaheadsSKG
CocoaheadsSKG
CocoaheadsSKG
self.hero.isEnabled = true
redView.hero.id = "ironMan"
blackView.hero.id = "batMan"
whiteView.hero.modifiers = [.translate(y:100)]
redView.hero.id = "ironMan"
blackView.hero.id = "batMan"
View controller 1
View controller 2
CocoaheadsSKG
CocoaheadsSKG
CocoaheadsSKG