Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
もっとFluidでRedirectableなモーダル表示アニメーション
Search
Kazuya Hirobe
September 13, 2018
490
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
もっとFluidでRedirectableなモーダル表示アニメーション
Kazuya Hirobe
September 13, 2018
More Decks by Kazuya Hirobe
See All by Kazuya Hirobe
iPhoneXのホームに戻るみたいなDissmisアニメーション
hirobe
0
1.5k
Featured
See All Featured
Information Architects: The Missing Link in Design Systems
soysaucechin
0
980
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
210
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
170
Visualization
eitanlees
152
17k
The untapped power of vector embeddings
frankvandijk
2
1.8k
Google's AI Overviews - The New Search
badams
0
1k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
860
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Transcript
ͬͱFluidͰ RedirectableͳϞʔμϧ දࣔΞχϝʔγϣϯ @hirobe 2018.9.13
ࣗݾհ ෦Ұ ( twitter : @hirobe ) גࣜձࣾBunguu iOSΞϓϦɺMacOSΞϓϦͷ։ൃΛͬͯ·͢ ࠓճͷιʔείʔυ:
https://github.com/hirobe/DismissFluidlySample
Designing Fluid Interfaces (WWDC 2018) • Fluid : ྲྀମͷɺͳΊΒ͔ͳ •
ӳޠ͔͚ͬͨ͠Ͳɺࠓࣈນ͋Δ https://developer.apple.com/videos/play/wwdc2018/803/
What makes an interface feed fluid? • ͳΊΒ͔ͳΠϯλϑΣʔεͬͯͲΜͳͩΖ͏ʁ • ৮ͬͯͬ͘͠Γ͘Δͷ
A tool feels like an extension of your mind •
৺ ମͷԆͷΑ͏ʹײ͡ΒΕΔಓ۩ • iPhoneखͰૢ࡞͢Δͷ • ͏·͘ಈ͚ਓؒͷExtensionͱͳΕΔ • ৮Δͷָ͕͘͠ͳΔ
಄ͷಇ͖ํʹΞϓϦͷԠΛ߹ΘͤΔ • Ԡ͕େࣄ • ࢥߟͷํసׂΓࠐΈʹରԠ͠·͠ΐ͏ • ۭؒతҰ؏ੑΛอͬͨஔΛ͠Α͏ • Ϣʔβͷ༧ଌʹԊͬͨදݱΛ͠Α͏ •
খ͞ͳλονૢ࡞Ͱେ͖ͳग़ྗΛ͠Α͏ • εΫϩʔϧͷڥքʹόϯυΛ͚ͭΑ͏ • ΞχϝʔγϣϯͷνϥπΩΛࢭ͠Α͏
Redirectable • ࢥߟͷํసׂΓࠐΈʹଈԠ͠·͠ΐ͏ ਓؒߟ͑ͳ͕Βը໘ૢ࡞͢Δ • δΣενϟதͷδΣενϟΛՄೳʹ͠Α͏
δΣενϟதͷδΣενϟ iPhoneX • ϗʔϜʹΓͳ͕Β ϗʔϜը໘ΛԣεϫΠϓ
δΣενϟதͷδΣενϟ iPhoneX • ΞϓϦΛλοϓͯ͠ ֦େதʹϗʔϜը໘ʹΔ
δΣενϟதͷδΣενϟ iPhoneX • ΞϓϦΛىಈͯ͠ ֦େதʹΞϓϦΛૢ࡞
ΞϓϦͰ࣮͍ͨ͠ʂ • Ͳ͜Ͱ͑ΔͩΖ͏͔ʁ • ͦ͏͍͑ࢥ͍ͨΔ͜ͱ͕
ࣸਅΛλοϓ͢Δͱ֦େදࣔ͢ΔΞϓϦ
λον͕ແࢹ͞ΕΔ͜ͱ͕͋Δ • ࢠը໘Λดͨ͡ޙʹɺ ผͷը૾Λ։͖͍ͨ • ը૾ͷॖখΞχϝʔγϣ ϯ͕ऴΘΔલʹλοϓ͠ ͪΌͬͯΔʁʁ /P 3FTQPOTF
iPhoneXͷϗʔϜͷ߹
iPhoneXͷϗʔϜͷ߹ • ΞϓϦΛด͍ͯΔؒɺ λονΛͪΌΜͱड͚͚ͯ ͘ΕΔ -> Fluid!
ը໘Λด͡ΔભҠதʹ ผૢ࡞Λ ड͚͚ΔͷΛ ΞϓϦͰ࣮ݱ͢Δͧ
UIViewControllerAnimatedTransitioning • containerViewʹదʹviewΛషΓ͚ͯ ը໘ભҠΞχϝʔγϣϯΛॻ͍͓ͯ͘ Ξχϝʔγϣϯ༻ͷ View containerView ը໘
UIViewControllerAnimatedTransitioning • ç func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { if isForPresented
{ // present presentAnimation(transitionContext) } else { // dissmis dissmisAnimation(transitionContext) } } func dissmisAnimation(_ transitionContext: UIViewControllerContextTransitioning) { let containerView = transitionContext.containerView guard let nav = transitionContext.viewController(forKey: .from) as? UINavigationController, let detailVC:DetailViewController = nav.visibleViewController as? DetailViewController else { fatalError() }
UIViewControllerAnimatedTransitioning • ç let fromImageRect = detailVC.detailImageRect(containerView: containerView, safeAreaInsets: from?.view?.safeAreaInsets
?? .zero) let toImageRect = detailVC.parentImageViewRect // imageΛҠಈ͢ΔͨΊͷviewΛ࡞ let imageView:UIImageView = UIImageView(frame: fromImageRect) imageView.contentMode = .scaleAspectFill imageView.clipsToBounds = true imageView.image = detailVC.parentImage containerView.addSubview(imageView) // ॖখΞχϝʔγϣϯ nav.view.isHidden = true UIView.animate(withDuration: transitionDuration(using: transitionContext), delay: 0, options: [.curveEaseInOut], animations: { () -> Void in imageView.frame = toImageRect }) { (finished) -> Void in nav.view.removeFromSuperview() transitionContext.completeTransition(true) } }
ࢦΛͨ͠ޙͷΞχϝʔγϣϯ • UIViewControllerTransitionDelegate, UIViewControllerAnimatedTransitioningΛ࣮ • ։࣌͘ʹtransitionDelegateʹηοτ override func collectionView(_ collectionView:
UICollectionView, didSelectItemAt indexPath: IndexPath) { : let storyboard = UIStoryboard(name: "Main", bundle: nil) guard let vc = storyboard.instantiateViewController(withIdentifier: "DetailViewController") as? DetailViewController else { return } let nav = UINavigationController(rootViewController: vc) nav.isNavigationBarHidden = true nav.modalPresentationStyle = .custom nav.transitioningDelegate = vc.modalTransition self.present(nav, animated: true) }
• dismiss(animated: true)ͰΞχϝʔγϣϯΛ։࢝ • λονδΣενϟ͕ແࢹ͞ΕΔ εϫΠϓɺϘλϯૢ࡞ ࢦΛͨ͠:dismiss(animated: true) ด͡ΔΞχϝʔγϣϯ UIViewController
AnimatedTransitioning UIViewControllerAnimatedTransitioning
UIAnimatedTransitioningΛΘͳ͍ ->ࢦΛͨ͠ޙɺભҠઌ͕Ξχϝʔγϣϯ εϫΠϓɺϘλϯૢ࡞ ࢦΛͨ͠: dismiss(animated: false) ࢠViewCotroller ด͡ΔΞχϝʔγϣϯ ʢ৮ΕΔʣ ViewCotroller
λοϓ͕ແࢹ͞Εͳ͘ͳͬͨ • Ͱ͖ͨʂ
͚ͩͲɺɺ
FatͳViewControllerʹͳΔ ΑͶ →ͳΜͱ͔͍ͨ͠ ͚ͩͲɺɺ
UIViewControllerAnimatedTransitioningΛ ྲྀ༻͠Α͏ class DetailModalTransition : NSObject, UIViewControllerTransitioningDelegate, UIViewControllerAnimatedTransitioning { func
animateTransition(using transitionContext: UIViewControllerContextTransitioning) { if isForPresented { // present // : } else { // dissmis self.dissmisAnimation( containerView: transitionContext.containerView, from: transitionContext.viewController(forKey: .from), to: transitionContext.viewController(forKey: .to), duration: self.transitionDuration(using: transitionContext), completeTransition: transitionContext.completeTransition) } } func dissmisAnimation(containerView: UIView, from: UIViewController?, to: UIViewController?, duration: TimeInterval, completeTransition: @escaping (_ didComplete: Bool) -> Void) { // ΞχϝʔγϣϯΛॻ͘ } }
extension DetailModalTransition { func dissmisFluidly(viewController:UIViewController?) { guard let parent =
viewController?.presentingViewController, let child = parent.presentedViewController, let window = parent.view?.window else { return } viewController?.dismiss(animated: false) { // viewDidDisappearͷޙʹݺΕΔͷͰҙ let containerView = UIView(frame: window.bounds) containerView.isUserInteractionEnabled = false window.addSubview(containerView) self.dissmisAnimation(containerView: containerView, from: child, to: parent, duration: 0.6, completeTransition: { didComplete in containerView.removeFromSuperview() }) } } } UIViewControllerAnimatedTransitioningΛ ྲྀ༻͠Α͏
·ͱΊ • ը໘ભҠΞχϝʔγϣϯதʹλονΛ༗ޮʹͨ͠ • ࢦΛͨ͠ޙɺભҠઌͷViewControllerͰॲཧ͢Δ • λον͕ແࢹ͞Εͳ͘ͳͬͨ • Fluidʹͳͬͨʂʂ •
͏ͪΐͬͱεϚʔτͳΓํͳ͍ͷ͔ Github : https://github.com/hirobe/DismissFluidlySample