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
59
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
470
自社コンテンツ配信 のためのWebView Tips
gentlesoft
2
5.6k
実践Protocol-Extension
gentlesoft
0
84
UIKitDynamicsの活用法
gentlesoft
0
610
iOS9のUIKitDynamics
gentlesoft
0
50
CoreDataによるデータ駆動型プログラミング
gentlesoft
0
200
Other Decks in Programming
See All in Programming
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
130
Vite+ Unified Toolchain for the Web
naokihaba
0
310
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
11
4.1k
net-httpのHTTP/2対応について
naruse
0
480
気圧・高度・GPSを記録&可視化するアプリ「Koudo」を作った話
hjmkth
1
260
ふつうのFeature Flag実践入門
irof
7
3.9k
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
260
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
540
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
4k
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
120
依存関係から依存物へ―Dependencyという言葉の歴史をひも解く
j_lee
0
120
Oxlintのカスタムルールの現況
syumai
6
1.1k
Featured
See All Featured
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Heart Work Chapter 1 - Part 1
lfama
PRO
7
36k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.6k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
HDC tutorial
michielstock
2
710
Odyssey Design
rkendrick25
PRO
2
700
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Marketing to machines
jonoalderson
1
5.4k
What does AI have to do with Human Rights?
axbom
PRO
1
2.2k
Tell your own story through comics
letsgokoyo
1
950
Ethics towards AI in product and experience design
skipperchong
2
310
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
160
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ͷՃ࣌ʹҰॠΞχϝʔγϣϯ͕ࢭ·Δ • ͱ͖͓Γಈ͔ͳ͘ͳΔɾɾɾ
̍प͓ΊͰͱ͏ ͍͟͝·͢