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
UIKitDynamicsの活用法
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Shinji Kobayashi
March 05, 2016
Programming
620
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
UIKitDynamicsの活用法
yidev 第22回勉強会
2016年3月5日
Shinji Kobayashi
March 05, 2016
More Decks by Shinji Kobayashi
See All by Shinji Kobayashi
5分でできる UITableViewのDrag & Drop
gentlesoft
0
480
自社コンテンツ配信 のためのWebView Tips
gentlesoft
2
5.7k
実践Protocol-Extension
gentlesoft
0
85
iOS9のUIKitDynamics
gentlesoft
0
53
SwiftでUIKitDynamics
gentlesoft
0
60
CoreDataによるデータ駆動型プログラミング
gentlesoft
0
200
Other Decks in Programming
See All in Programming
React本体のコードリーディング
high_g_engineer
1
150
MySQLとPostgreSQLって何が違うの?
akagami
0
120
「人を評価する AI」の設計と実装
ryoyanara
0
220
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
490
これって Effect でできたのでは? / TSKaigi Mashup Kansai #2
susisu
0
250
全PRの83%がAIレビューだけでマージできるようになった開発組織はその後どうなったか
athug
1
1.9k
片田舎のおっさん、 Swift Buildのダイアモンド問題解決の不具合修正PRを出すが、解決方法がキャッシュをしないようにすることであり、ビルド時間が伸びると言われてマージされないので高速化もする/swiftbuild
yimajo
0
220
レビュー履歴をAIに食わせて、 Compose移行を加速するs
shihochan
0
160
Jindong: Introducing Declarative Haptics in Compose Multiplatform
l2hyunwoo
0
120
KotlinConf Extended South Korea 2026 Keynote
l2hyunwoo
0
120
「寝てても仕事が進む」Claude Codeで組む第二の脳
tomoyafujita2016
0
350
SlackアプリとLambdaの 連携を構築した話
pawn_4_s
1
130
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.9k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
790
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
500
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
HDC tutorial
michielstock
2
800
How to Talk to Developers About Accessibility
jct
2
520
The Cost Of JavaScript in 2023
addyosmani
55
10k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3k
Code Review Best Practice
trishagee
74
20k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
440
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
430
The SEO Collaboration Effect
kristinabergwall1
1
530
Transcript
UIKitDynamicsͷ׆༻๏ Shinji Kobayashi GentleSoft yidev ୈ̎̎ճษڧձ
NameɿShinji Kobayashi Twitterɿ@gentlejkov GentleSoft Who are you? http://gentlesoft.net
2DͷཧԋࢉΛͬͨΞχϝʔγϣϯ͕ ؆୯ʹ࡞Ͱ͖ΔϥΠϒϥϦ UIKitDynamicsͱ ௨ৗͷΞϓϦέʔγϣϯதʹཧԋࢉͷ ΞχϝʔγϣϯΛ؆୯ʹಋೖͰ͖Δ
2DͷཧԋࢉΛͬͨΞχϝʔγϣϯ͕ ؆୯ʹ࡞Ͱ͖ΔϥΠϒϥϦ UIKitDynamicsͱ ௨ৗͷΞϓϦέʔγϣϯதʹཧԋࢉͷ ΞχϝʔγϣϯΛ؆୯ʹಋೖͰ͖Δʁ
UIKitDynamicsͷಛ •ඪ४Ͱ༻ҙ͞Ε͍ͯΔ༰ͳΒෛՙͰ ཧԋࢉΛ࣮Ͱ͖Δ •࣮ࣗମׂͱ؆୯ •iOS8·Ͱඪ४ͷػೳ͕Γͳ͔ͬͨ ͕ɺiOS9ͰͷػೳՃʹΑΓඞཁͳཧԋ ࢉ͕ग़ἧ͖ͬͯͨ
UIKitDynamicsͷ •ཧԋࢉʹԊΘͳ͍ಈ͖Ͱ͖ͳ͍ •ࢥͬͨ௨Γʹಈ͔͢ͷ͍͠ •Կʹ͍͍͑ͷ͔͔Βͳ͍
UIKitDynamicsͷ͍ಓ •UIViewΛཧԋࢉʹԊͬͨΞχϝʔγϣϯ ͤͯ͞ɺϦονͳදݱΛ͢Δ •ը໘ભҠʹཧԋࢉͷΞχϝʔγϣϯΛऔ ΓೖΕͯ༡Ϳ
UIDynamicItemϓϩτίϧΛ࣮ͨ͠Ϋϥε UIKitDynamicsͷର •UIView •UICollectionViewLayoutAttributes UICollectionViewͷCustumLayoutΛ͏
• UIAttachmentBehaviorɹ-ɹόω • UICollisionBehaviorɹ-ɹিಥ • UIGravityBehaviorɹ-ɹॏྗ • UIDynamicItemBehaviorɹ-ɹମͷಛੑ • UIPushBehaviorɹ-ɹΤωϧΪʔ
• UISnapBehaviorɹ-ɹҠಈ UIKitDynamics(ʙiOS8)
Demo UIKitDynamics(ʙiOS8)
• UIDynamicItemCollisionBoundsType • UIFieldBehavior • linearGravityFieldWithVectorɹ-ɹॏྗۭؒ • radialGravityFieldWithPosition -Ҿྗʗి࣓ྗ •
noiseFieldWithSmoothness:animationSpeed • UIAttachmentBehavior 1. limitAttachmentWithItemɹ-ɹϩʔϓ 2. pinAttachmentWithItem - Google 13Hit 3. slidingAttachmentWithItem - Google 9Hit 4. fixedAttachmentWithItem - Google 10Hit UIKitDynamics(iOS9ʙ)
Demo
UIDynamicAnimatorͷΦϒδΣΫτΛ࡞ ࣮खॱ ඞཁͳBehaviorΛ࡞͠ɺΞχϝʔγϣϯ ͍ͤͨ͞ViewΛηοτ UIDynamicAnimatorʹBehaviorΛηοτ
࣮ʢൈਮʣ animator = UIDynamicAnimator(referenceView: source) let gravity = UIGravityBehavior(items: [destination])
gravity.magnitude = 12 let collision = UICollisionBehavior(items: [destination]) collision.addBoundaryWithIdentifier("bottom", fromPoint: CGPoint(x: 0, y: source.bounds.height), toPoint: CGPoint(x: source.bounds.width, y: source.bounds.height)) let item = UIDynamicItemBehavior(items: [destination]) item.elasticity = 0.5 item.resistance = 0.8 animator.delegate = self animator.addBehavior(gravity) animator.addBehavior(collision) animator.addBehavior(item)
CollectionViewLayoutΛܧঝͯ͠CustomLayoutΛ࡞ ࣮खॱ(UICollectionView) override func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes! { return
animator.layoutAttributesForCellAtIndexPath(indexPath) } override func layoutAttributesForElementsInRect(rect: CGRect) -> [AnyObject]? { return animator.itemsInRect(rect) } animator = UIDynamicAnimator(collectionViewLayout: self) ఆܕจ
ٙ Animator͕ىಈͨ࣌͠Ͱແࢹ͞ΕΔ ઃఆͨ͠AutoLayoutͲ͏ͳΔʁ
ٙ ϦΞϧλΠϜʹऔΕΔɺ༏ल UIViewͷframe͔Β࠲ඪऔΕΔʁ
ٙ GestureRecognizerͬͪΓ͑Δ ΞχϝʔγϣϯதͷViewͷλονఆʁ
ٙ ແཧɺແବ UIViewͷframeʹҙͷ࠲ඪΛ ઃఆͯ͠ViewΛಈ͔ͤΔʁ
ٙ ViewΛૢ࡞͍ͨ࣌͠Ͳ͏͢Δʁ UIAttachmentBehaviorʹૢ࡞͍ͨ͠Viewͱ Ҡಈ͍ͨ͠ҐஔͷanchorPointΛࢦఆɺ lengthΛ0ʹ͢Δͱૂ͍ͷҐஔʹಈ͔ͤΔ
ٙ Ξχϝʔγϣϯ͕ऴྃͨ͠ఆʁ ͯ͢ͷΦϒδΣΫτ͕ఀࢭͨ࣌͠ɺ UIDynamicAnimatorDelegateͷ dynamicAnimatorDidPauseϝιου͕ݺΕΔ
ٙ Ξχϝʔγϣϯ͕ऴྃͨ͠Β View͕ݩͷҐஔʹͬͨΓ͢Δʁ ͠ͳ͍ AnimatorΛআͯ͠ɺViewͷҐஔͦͷ··
ٙ ͦͷ࣌ͷAutoLayoutʁ ͔Γ·ͤΜ
·ͱΊ •UIKitDynamicsUIViewͱUICollectionView Ͱ͑ͯɺͦͷ࣮ࣗମ༰қ •େͷύλʔϯͷཧԋࢉΛඪ४ػೳͰ࣮ Ͱ͖ΔΑ͏ʹͳͬͨ •ΞχϝʔγϣϯΛϦΞϧλΠϜʹิͯ͠ɺ ૢ࡞͢Δ͜ͱ͕Ͱ͖ΔͷͰɺΠϯλϥΫςΟ ϒͳΞχϝʔγϣϯʹ͍͍ͯΔ
UIKitDynamicsΛ׆༻ͯ͠ ΠϯλϥΫςΟϒͰ ΞχϝʔγϣϯϦονͳ ΞϓϦΛ࣮͠Α͏ʂ