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
Swipe Transition
Search
Tatsuya Tanaka
January 24, 2018
Technology
1.9k
12
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Swipe Transition
#potatotips 47
https://github.com/tattn/SwipeTransition
Tatsuya Tanaka
January 24, 2018
More Decks by Tatsuya Tanaka
See All by Tatsuya Tanaka
iPhoneのセンサー情報をmacOSアプリでリアルタイム活用するための技術
tattn
1
790
Better use of SwiftUI
tattn
0
510
Swift Concurrencyによる安全で快適な非同期処理
tattn
2
1.5k
iOSアプリの技術選択2022
tattn
7
4k
Widget Suggestions 対応と ヤフーの新OS対応
tattn
1
1.4k
WidgetKitで良い体験を作るには / Good experience with WidgetKit
tattn
2
2k
既存アプリにSwiftUIをどう組み込んでいくか
tattn
8
2.6k
iOS 14からのアプリ内課金
tattn
5
3.2k
iOS 14の位置情報系アップデート
tattn
0
22k
Other Decks in Technology
See All in Technology
英語が話せなくてもKubeConスタッフに参加した話
yusuke427
2
1.1k
案件に一番詳しいAIを Amazon Bedrock AgentCore で作る ― 知見が知見を生むチームへ / Compounding Knowledge with AgentCore
yusukeshimizu
1
170
MIXIで活躍できるエンジニアを 若手社員目線で考えてみる
mixi_engineers
PRO
0
140
AIに持続⼒を与える 判断の⻑期記憶設計
eiei114
1
680
LanceDB入門
mocobeta
9
670
ハッカソンで入賞した話 @ Findy LT
asari194617
0
1.5k
ホームラボ紹介
y_sera15
0
230
Oracle MCP Servers Explained
thatjeffsmith
0
440
MulticaとPi Coding Agentで、小規模OSSを30本同時運用した流れ
eiei114
0
140
あなたの知らないバージョン命名規則
sat
PRO
2
330
2026-08-15 JAWS-UG 茨城 #16 Secrets ManagerにおけるSecret値の管理(Terraformの場合) / Secrets Manager Secrets
masasuzu
0
560
わたしが知り合いゼロの勉強会に 行けるようになるまで
r5ni4
1
170
Featured
See All Featured
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.8k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
250
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
620
Bash Introduction
62gerente
615
220k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Google's AI Overviews - The New Search
badams
0
1.1k
Utilizing Notion as your number one productivity tool
mfonobong
4
550
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
66
57k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
380
Transcript
Swipe Transition #potatotips 47 ాத ୡ (@tattn)
• Yahoo!Ҋ • iOSΞϓϦΤϯδχΞ • GitHub: @tattn • Qiita: @tattn
• Twitter: @tanakasan2525 ాத ୡ (@tattn)
Α͋͘Δ ศརͳεϫΠϓδΣενϟʔ Λ࣮ͯ͠Έ·ͨ͠
ͲͷҐஔͰ εϫΠϓόοΫͰ͖Δ
ը໘ͷͲ͜ͰࠨʹεϫΠϓͰ͖Δ ը໘(Τοδ)Ͱͳͯ͘OK
Sloppy Swiping ͱݺΕ͍ͯ·͢ɻ ͜ͷεϥΠυͰγϯϓϧʹ SwipeBackͱදه͠·͢ɻ
ԼεϫΠϓͰϞʔμϧΛด͡Δ
ԼʹεϫΠϓ͢ΔͱϞʔμϧͷը໘͕εϫΠϓͱͱʹҠಈ͠ɺ ͋ΔఔεΫϩʔϧ͢Δͱด͡Δ
͜ͷεϥΠυͰ SwipeToDismissͱදه͠·͢ɻ
࣮ͯ͠Έ·ͨ͠ͷͰɺ ͦͷ࣮ํ๏Λ͝հ͠·͢
࣮ํ๏
ࠓճͷओͳొਓ • UIPanGestureRecognizer • UIViewControllerAnimatedTransitioning • UIViewControllerTransitioningDelegate • UINavigationControllerDelegate
• UIPercentDrivenInteractiveTransition
UIPanGestureRecognizer ࢦͷҠಈྔͳͲΛऔಘͰ͖ΔΫϥεɻ ࠓճ͜ΕͰεϫΠϓΛݕग़͠·͢ɻ IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOVJLJUVJQBOHFTUVSFSFDPHOJ[FS
UIViewControllerAnimatedTransitioning ࣗ࡞ͷը໘ભҠΛ࣮Ͱ͖Δϓϩτίϧɻ SwipeBackͰViewΛӈʹҠಈɺ SwipeToDismissͰViewΛԼʹҠಈ ͢ΔͨΊʹ༻͠·͢ɻ IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOVJLJUVJWJFXDPOUSPMMFSBOJNBUFEUSBOTJUJPOJOH
UIViewControllerTransitioningDelegate present/dismiss࣌ʹ Ͳͷτϥϯδγϣϯ(UIViewControllerAnimatedTransitioning)Λ ར༻͢Δͷ͔Λࢦఆ͢Δϓϩτίϧɻ SwipeToDismissͰࣗ࡞ͷը໘ભҠΛར༻͢ΔͨΊʹ ༻͠·͢ɻ IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOVJLJUVJWJFXDPOUSPMMFSUSBOTJUJPOJOHEFMFHBUF
UINavigationControllerDelegate UINavigationControllerͰൃੜ͢ΔΠϕϯτͷัଊ Ͳͷτϥϯδγϣϯ(UIViewControllerAnimatedTransitioning)Λ ར༻͢Δͷ͔Λࢦఆ͢Δϓϩτίϧɻ SwipeBackͰࣗ࡞ͷը໘ભҠΛར༻͢ΔͨΊʹ ༻͠·͢ɻ IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOVJLJUVJOBWJHBUJPODPOUSPMMFSEFMFHBUF
UIPercentDrivenInteractiveTransition ը໘ભҠͷิؒํ๏ͷࢦఆ ը໘ભҠ͕Կ%͍ྃͯ͠Δͷ͔ͳͲΛ ઃఆ͢ΔΫϥεɻ SwipeBackͱSwipeToDismissͰ Ͳ͜·ͰεϫΠϓͨ͠ͷ͔Λදݱ͢ΔͨΊʹ༻͠·͢ɻ IUUQTEFWFMPQFSBQQMFDPNEPDVNFOUBUJPOVJLJUVJQFSDFOUESJWFOJOUFSBDUJWFUSBOTJUJPO
(ൃද࣌ؒͷؔͰ) SwipeBackͷํΛհ͠·͢ɻ (SwipeToDismiss΄΅ಉ࣮͡Ͱग़དྷ·͢ɻ)
SwipeBackAnimator class SwipeBackAnimator: NSObject, UIViewControllerAnimatedTransitioning { func animateTransition(using transitionContext:
UIViewControllerContextTransitioning) { guard let to = transitionContext.viewController(forKey: .to), let from = transitionContext.viewController(forKey: .from) else { return } let containerView = transitionContext.containerView containerView.insertSubview(to.view, belowSubview: from.view) to.view.frame = containerView.frame ભҠݩͷviewͷԼʹભҠޙͷviewΛinsert͍ͯ͠·͢ɻ SwipeBack࣌ʹԼͷViewΛදࣔ͢ΔͨΊͰ͢ɻ
͜ͷ෦
SwipeBackAnimator // ύϥϥοΫεޮՌ to.view.transform.tx = -containerView.bounds.width * 0.3 UIView.animate(
withDuration: transitionDuration(using: transitionContext), delay: 0, options: .curveLinear, animations: { to.view.transform = .identity from.view.transform = CGAffineTransform(translationX: to.view.frame.width, y: 0) }, completion: { _ in from.view.transform = .identity transitionContext.completeTransition( !transitionContext.transitionWasCancelled ) }) ભҠޙͷviewʹύϥϥοΫεޮՌΛ͚ͭͭɺ ભҠલͷviewΛӈҠಈ
SwipeBackNavigationController class SwipeBackNavigationController: UINavigationController { private let animator =
SwipeBackAnimator() private var interactiveTransition: UIPercentDrivenInteractiveTransition! override func viewDidLoad() { super.viewDidLoad() delegate = self let panGesture = UIPanGestureRecognizer() panGesture.addTarget(self, action: #selector(handlePanGesture(_:))) panGesture.maximumNumberOfTouches = 1 view.addGestureRecognizer(panGesture) } viewʹUIPanGestureRecognizerͱ UINavigationControllerDelegateΛηοτ
SwipeBackNavigationController extension SwipeBackNavigationController: UINavigationControllerDelegate { public func navigationController(_ navigationController:
UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { return operation == .pop ? animator : nil } public func navigationController(_ navigationController: UINavigationController, interactionControllerFor animationController: UIViewControllerAnimatedTransitioning) -> UIViewControllerInteractiveTransitioning? { return interactiveTransition } } ར༻͢Δࣗ࡞ͷτϥϯδγϣϯΛฦ͢ɻ (εϥΠυʹࡌͤΔͱਏ͍ݟͨͰ͕͢ɺ࣮͍ͯ͠Δͷ2ߦͰ͢)
SwipeBackNavigationController @objc private func handlePanGesture(_ recognizer: UIPanGestureRecognizer) { switch
recognizer.state { case .began: interactiveTransition = UIPercentDrivenInteractiveTransition() interactiveTransition.completionCurve = .linear popViewController(animated: true) case .changed: let translation = recognizer.translation(in: view) interactiveTransition.update(translation.x / view.bounds.width) case .ended: if recognizer.velocity(in: view).x > 0 { interactiveTransition.finish() interactiveTransition = nil } else { fallthrough } case .cancelled: interactiveTransition.cancel() interactiveTransition = nil default: break } } δΣενϟʔʹ߹Θͤͯঢ়ଶΛߋ৽
100ߦຬͨͳ͍ίʔυͰ γϯϓϧͳSwipeBackΛ࣮Ͱ͖·ͨ͠ɻ ࠓճͷ࣮ˣʹஔ͍ͯ͋Γ·͢ɻ https://github.com/tattn/SwipeTransitionExample
ϥΠϒϥϦԽ
͔ͤͬ͘ͳͷͰϥΠϒϥϦԽ͠·ͨ͠ https://github.com/tattn/SwipeTransition ScrollView͕͋ͬͯಈ࡞͢ΔΑ͏ʹͨ͠Γɺ Method SwizzlingͰશը໘ʹద༻͢Δػೳ͋Γ·͢ɻ SwipeTransition ͥͻɺ͓ࢼ͍ͩ͘͠͞ʂ
·ͱΊ
·ͱΊ ʘδΣενϟʔͰૉఢUXΛࢦͦ͏ʗ ʘʘ\\٩( 'ω' )و //ʗʗ ఏڙ͞Ε͍ͯΔΈΛར༻͢Δ͜ͱͰ ҙ֎ͱ؆୯ʹ࣮͢Δ͜ͱ͕ग़དྷ·ͨ͠