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
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
85
UIKitDynamicsの活用法
gentlesoft
0
620
iOS9のUIKitDynamics
gentlesoft
0
53
CoreDataによるデータ駆動型プログラミング
gentlesoft
0
200
Other Decks in Programming
See All in Programming
自動化したのに回らないテスト運用の壁ーAI時代の品質責任と生産性
mfunaki
1
150
freeeにおけるEvalsの実践例の紹介
freee
PRO
0
140
人間の目はかわらない、だからJPEGは30年もつ
yuzneri
12
19k
Detecting Compromised CI with eBPF and Cilium Tetragon
lizrice
0
230
テーブルをDELETEした
yuzneri
0
150
生成AI導入の「期待外れ」を乗り越える ー 開発フロー改革が目指す、真の組織変革
starfish719
0
5k
仕様駆動開発へのトライを機に チームに適合する手法を模索し続けている話
freee
PRO
0
590
使いながら育てる Claude Code — 開発フローの1コマンド化 × 繰り返し指摘の自動仕組み化
shiki_kakaku
0
1.9k
VibeCodingからAgenticWorkflowへ
starfish719
0
730
「つくるAI」だけではバグは見つからない ~テストに必要な「見つけるAI」を分離させる戦略~
mfunaki
0
130
typoなんかねぇよ
raspython3
0
190
書籍「プロフェッショナルAI駆動開発」紹介スライド
juntaromatsumoto
0
260
Featured
See All Featured
Between Models and Reality
mayunak
4
400
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
Designing for Performance
lara
611
70k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.5k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
4.4k
Balancing Empowerment & Direction
lara
6
1.2k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
390
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.6k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Context Engineering - Making Every Token Count
addyosmani
9
1.1k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
480
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
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ͷՃ࣌ʹҰॠΞχϝʔγϣϯ͕ࢭ·Δ • ͱ͖͓Γಈ͔ͳ͘ͳΔɾɾɾ
̍प͓ΊͰͱ͏ ͍͟͝·͢