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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
Paper Plane (Part 1)
katiecoart
PRO
0
9.2k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
11k
Why Our Code Smells
bkeepers
PRO
340
58k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.6k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Prompt Engineering for Job Search
mfonobong
0
350
Building an army of robots
kneath
306
46k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
A better future with KSS
kneath
240
18k
Visualization
eitanlees
152
17k
How to Think Like a Performance Engineer
csswizardry
28
2.7k
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