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
Shinji Kobayashi
March 05, 2016
Programming
610
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
470
自社コンテンツ配信 のためのWebView Tips
gentlesoft
2
5.6k
実践Protocol-Extension
gentlesoft
0
84
iOS9のUIKitDynamics
gentlesoft
0
50
SwiftでUIKitDynamics
gentlesoft
0
59
CoreDataによるデータ駆動型プログラミング
gentlesoft
0
200
Other Decks in Programming
See All in Programming
Agentic UI
manfredsteyer
PRO
0
160
Signal Forms: Details & Live Coding @enterJS 2026 in Mannheim
manfredsteyer
PRO
0
140
ふつうのFeature Flag実践入門
irof
7
3.9k
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
140
Claspは野良GASの夢をみるか
takter00
0
190
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
540
Inside Stream API
skrb
1
710
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
250
The NotImplementedError Problem in Ruby
koic
1
790
ユニットテストの先へ:テスト技法で要求・仕様を整理するJava開発実践 / Beyond_Unit_Testing_Practical_Java_Development_Techniques_for_Organizing_Requirements_and_Specifications
shimashima35
0
400
CSC307 Lecture 17
javiergs
PRO
0
320
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
120
Featured
See All Featured
Building the Perfect Custom Keyboard
takai
2
790
Test your architecture with Archunit
thirion
1
2.3k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
390
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
1.4k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
480
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
240
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
270
The Spectacular Lies of Maps
axbom
PRO
1
810
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Docker and Python
trallard
47
3.9k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.1k
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Λ׆༻ͯ͠ ΠϯλϥΫςΟϒͰ ΞχϝʔγϣϯϦονͳ ΞϓϦΛ࣮͠Α͏ʂ