Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
SwiftでUIKitDynamics
Search
Shinji Kobayashi
December 18, 2014
Programming
60
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
480
自社コンテンツ配信 のためのWebView Tips
gentlesoft
2
5.7k
実践Protocol-Extension
gentlesoft
0
86
UIKitDynamicsの活用法
gentlesoft
0
620
iOS9のUIKitDynamics
gentlesoft
0
53
CoreDataによるデータ駆動型プログラミング
gentlesoft
0
200
Other Decks in Programming
See All in Programming
週末にAI-DLCを本気で回したら$1,600溶けた
hbashimizu
0
130
[DroidKaigi 2026] Bring your own phones to Gradle Managed Devices
f2lk
0
110
Intent as Code
shoppingjaws
5
710
自分的「カンファレンスの楽しみ方」
syumai
0
200
Seeing Through Serverless: Observability for AWS Lambda with ADOT and CloudWatch Application Signals
seike460
PRO
1
130
LL言語やWebフレームワークのPostgreSQL対応 〜DBの機能がユーザーに届くまで〜
kentaroutakeda
0
150
初心者DevRelとして参加者だった私が、DevRel Talks!#2に登壇するまでにしてきたこと
sokohirai
0
360
一参加者から『中の人』へ 〜全通PHPerがブースに立って学んだ、カンファレンスを100倍楽しむコツ〜
wp_daisuke
0
140
go-spidermonkeyでAIエージェントのCode Modeを実装する
syumai
3
1.5k
From 6 People Classroom Meetup to 100 People Regional Conference / FOSS4G Hiroshima 2026
furukawayasuto
0
130
変化を抱擁するドキュメントの作り方 - ビジネスルール駆動開発がもたらす、コードとの新しい関係
ioki
2
130
PHPプロジェクトの結合バランスを可視化する #php_night
kajitack
0
230
Featured
See All Featured
Everyday Curiosity
cassininazir
0
310
[SF Ruby Conf 2025] Rails X
palkan
2
1.4k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
How to Think Like a Performance Engineer
csswizardry
28
2.8k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.5k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
65k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
320
Building Adaptive Systems
keathley
44
3.2k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
For a Future-Friendly Web
brad_frost
183
10k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.3k
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ͷՃ࣌ʹҰॠΞχϝʔγϣϯ͕ࢭ·Δ • ͱ͖͓Γಈ͔ͳ͘ͳΔɾɾɾ
̍प͓ΊͰͱ͏ ͍͟͝·͢