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
Go × SIMDで高速化するベクトル検索 ~ルーフラインモデルでSIMDが効く境界を探れ! ~
po3rin
1
3.9k
技術的負債を組織課題として解く-増えすぎたマイクロサービスとの戦い-
reimaru
1
2.4k
FreeBSDでZabbixを動かす
kenkino
0
330
仕様駆動開発による爆速プロダクト開発 / Bakusoku Spec Driven Development
kobakei
0
140
巨大モノリシックアプリ モダン化大作戦
ktcryomm
1
1.1k
Workers Cache を知る
syumai
0
280
そのリトライ、死んだコネクションを使い回していませんか ── GoのHTTPクライアントとHTTP/2を実プロダクト障害から学び直す
myus4a
0
280
AgentCore CLI で進化した AWS での AI エージェントの作り方 : 必要な機能を必要な時に
icoxfog417
PRO
3
380
一人だけ、Kiroが静止する日
hideg
0
130
iOS 27でニュースアプリはどう変わる!? 〜日経電子版の新機能対応と、開発事例から〜
lynnswap
6
13k
【高い買い物LT会】初任給で話題の国産フィジカルAIを買った話
akagami
PRO
0
170
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
5k
Featured
See All Featured
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
450
Done Done
chrislema
187
17k
Marketing to machines
jonoalderson
1
5.8k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
540
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Rails Girls Zürich Keynote
gr2m
96
14k
Optimizing for Happiness
mojombo
378
71k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
490
How STYLIGHT went responsive
nonsquared
100
6.3k
Un-Boring Meetings
codingconduct
0
430
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
550
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ͷՃ࣌ʹҰॠΞχϝʔγϣϯ͕ࢭ·Δ • ͱ͖͓Γಈ͔ͳ͘ͳΔɾɾɾ
̍प͓ΊͰͱ͏ ͍͟͝·͢