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
500
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 AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.7k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
3
1.1k
Thoughts on Productivity
jonyablonski
76
5.3k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.7k
Large-scale JavaScript Application Architecture
addyosmani
515
110k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
170
GitHub's CSS Performance
jonrohan
1033
470k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.9k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
420
Practical Orchestrator
shlominoach
191
12k
The browser strikes back
jonoalderson
0
1.5k
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