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
SwiftでUIKitDynamics
Search
Shinji Kobayashi
December 18, 2014
Programming
59
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
SwiftでUIKitDynamics
Shinji Kobayashi
December 18, 2014
More Decks by Shinji Kobayashi
See All by Shinji Kobayashi
5分でできる UITableViewのDrag & Drop
gentlesoft
0
470
自社コンテンツ配信 のためのWebView Tips
gentlesoft
2
5.6k
実践Protocol-Extension
gentlesoft
0
84
UIKitDynamicsの活用法
gentlesoft
0
620
iOS9のUIKitDynamics
gentlesoft
0
50
CoreDataによるデータ駆動型プログラミング
gentlesoft
0
200
Other Decks in Programming
See All in Programming
Embedded SREと共に達成した会員管理システムのAWS移行 - SRE NEXT 2026 ランチスポンサーセッション
niftycorp
PRO
1
2.5k
Developing with AI Agents — Codex, Claude Code & Cowork Practical Guide
x5gtrn
PRO
0
1.4k
【やさしく解説 設計編 #1】「ドメイン駆動」と「実装駆動」ってなに? 〜設計の考え方を、たとえ話で学ぼう〜
panda728
PRO
1
120
壊れたパーサから始める関数型設計と構成的なパーサ #fp_matsuri
raiga0310
2
210
Laravel Boostに学ぶ、AIにPHPを書かせる技術 〜OSSの実装から蒸留するエージェント制御の王道〜
kentaroutakeda
3
390
SREは、MCPとSRE Agentをこう使え!
kazumax55
0
150
初めてのKubernetes 本番運用でハマった話
oku053
0
130
ランチタイムLT会3周年!ランチタイムLT会を3年間続けられたお話
y0hgi
1
140
そのテスト、説明できますか?~LWテスト戦略FW~のご紹介
nakahara
0
200
OSINT for SRE: 学術論文とポストモーテムから探る システム障害の共通パターン / SRE NEXT 2026
tomoyk
1
3.7k
任せる範囲はこう広がった / How the Scope of AI Delegation Has Expanded
nrslib
1
250
アルゴリズムは何を圧縮しているのか ─ Haskell から育った「圧縮代数」というメンタルモデル
naoya
16
3.5k
Featured
See All Featured
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
320
Practical Orchestrator
shlominoach
191
11k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
490
SEO for Brand Visibility & Recognition
aleyda
0
4.6k
Skip the Path - Find Your Career Trail
mkilby
1
170
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
240
It's Worth the Effort
3n
188
29k
First, design no harm
axbom
PRO
2
1.2k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
650
We Are The Robots
honzajavorek
0
280
What does AI have to do with Human Rights?
axbom
PRO
1
2.2k
Transcript
SwiftͰUIKitDynamics Shinji Kobayashi GentleSoft ͘͘iOS 1पLTձ@Retty
NameɿShinji Kobayashi Twitterɿ@gentlejkov GentleSoft Who are you? http://gentlesoft.net
https://github.com/gentlesoft/UIKitDynamicsTest
• ը໘ભҠ • UIViewΛಈ͔͢ • UICollectionViewͰଟͷΦϒ δΣΫτ੍ޚ UIDynamicsͷ͍ಓ
• ը໘ભҠ • UIViewΛಈ͔͢ • UICollectionViewͰଟͷΦϒ δΣΫτ੍ޚ UIDynamicsͷ͍ಓ
ը໘ભҠ override func viewDidLoad() { super.viewDidLoad() self.transitioningDelegate = self }
// MARK: - UIViewControllerAnimatedTransitioning func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? { return DropTransition() } func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { return DropTransition() } UIViewControllerTransitioningDelegateΛ࣮
ը໘ભҠ class DropTransition: NSObject, UIViewControllerAnimatedTransitioning, UIDynamicAnimatorDelegate { private var transitionContext
: UIViewControllerContextTransitioning? private lazy var gravity : UIGravityBehavior = { let gravity = UIGravityBehavior() gravity.gravityDirection = CGVector(dx: 0.5, dy: 1) return gravity }() private let collision = UICollisionBehavior() private lazy var dynamicItem : UIDynamicItemBehavior = { let dynamicItem = UIDynamicItemBehavior() dynamicItem.elasticity = 0.5 dynamicItem.resistance = 0.8 return dynamicItem }() private var animator : UIDynamicAnimator? ΠϯελϯεͷԆੜͱॳظԽศརʁ
ը໘ભҠ func transitionDuration(transitionContext: UIViewControllerContextTransitioning) -> NSTimeInterval { return 0 }
func animateTransition(transitionContext: UIViewControllerContextTransitioning) { self.transitionContext = transitionContext let from = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey )!.view let to = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey)! .view ɾɾɾΞχϝʔγϣϯΛηοτ } override func animationDidStop(anim: CAAnimation!, finished flag: Bool) { self.animator = nil } // MARK: - UIDynamicAnimatorDelegate func dynamicAnimatorDidPause(animator: UIDynamicAnimator) { self.transitionContext?.completeTransition(true) } ΞχϝʔγϣϯऴྃͰcompleteTransitionΛݺͿ
• ը໘ભҠ • UIViewΛಈ͔͢ • UICollectionViewͰଟͷΦϒ δΣΫτ੍ޚ UIDynamicsͷ͍ಓ
UIViewΛಈ͔͢ // MARK: Gesture func handleGesture(recognizer: UIPanGestureRecognizer) { switch recognizer.state
{ case UIGestureRecognizerState.Began: self.tapPos = self.attachment.anchorPoint case UIGestureRecognizerState.Changed: let pos = recognizer.translationInView(self.malletView) self.attachment.anchorPoint = CGPoint(x: self.tapPos.x + pos.x, y: self.tapPos.y + pos.y) default: break } } • UIViewͷλονఆGestureRecognizer͕͑Δ • ࢦఆϙΠϯτͷҠಈUIAttatchmentBehavior • Static͕͑ͳ͍ͷͪΐͬͱෆศʁ
• ը໘ભҠ • UIViewΛಈ͔͢ • UICollectionViewͰଟͷΦϒ δΣΫτ੍ޚ UIDynamicsͷ͍ಓ
UICollectionView + UIKitDynamics class SandboxLayout: UICollectionViewLayout, UIDynamicAnimatorDelegate { ɾɾɾ override
func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes! { var attr = self.animator.layoutAttributesForCellAtIndexPath(indexPath) if attr == nil { attr = UICollectionViewLayoutAttributes(forCellWithIndexPath: indexPath) attr.frame = self.sandBoxDelegate.initSand(indexPath) } return attr } • SwiftͬΆ͘ͳ͍࣮Λڧ͍ΒΕΔ • animatorͷItemͷՃ࣌ʹҰॠΞχϝʔγϣϯ͕ࢭ·Δ • ͱ͖͓Γಈ͔ͳ͘ͳΔɾɾɾ
̍प͓ΊͰͱ͏ ͍͟͝·͢