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
AppKit for UIKit developers
Search
Florian Kugler
October 05, 2014
Programming
0
310
AppKit for UIKit developers
Florian Kugler
October 05, 2014
Tweet
Share
More Decks by Florian Kugler
See All by Florian Kugler
Pragmatic Core Data
floriankugler
0
8.1k
Interactive Animations
floriankugler
1
230
Parallele Programmierung (German!)
floriankugler
0
840
Graphics Performance across iOS Devices
floriankugler
5
1.2k
A Guided Tour Through the SproutCore Jungle
floriankugler
0
1.1k
Other Decks in Programming
See All in Programming
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.7k
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
170
CSC509 Lecture 11
javiergs
PRO
0
180
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
890
エンジニアとして関わる要件と仕様(公開用)
murabayashi
0
280
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
110
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
600
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
AI時代におけるSRE、 あるいはエンジニアの生存戦略
pyama86
6
1.1k
初めてDefinitelyTypedにPRを出した話
syumai
0
400
Outline View in SwiftUI
1024jp
1
330
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
Ruby is Unlike a Banana
tanoku
97
11k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Rails Girls Zürich Keynote
gr2m
94
13k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
109
49k
Embracing the Ebb and Flow
colly
84
4.5k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
860
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2.1k
Transcript
APPKIT for UIKIT%DEVELOPERS ! @FLORIANKUGLER #Pragma'Conference'2014
#Pragma'Conference'2014
#Pragma'Conference'2014
#Pragma'Conference'2014
#Pragma'Conference'2014
#Pragma'Conference'2014
SIMILARITIES #Pragma'Conference'2014
SHARED'FRAMEWORKS Founda'on Core%Graphics Core%Data Core%Anima+on ... #Pragma'Conference'2014
UIWindow & NSWindow #Pragma'Conference'2014
UIViewController & NSViewController #Pragma'Conference'2014
UIView & NSView #Pragma'Conference'2014
UIControl & NSControl #Pragma'Conference'2014
CONCEPTUALLY+SIMILAR,+PRACTICALLY+ NOT+SO+MUCH UIWindow)≠)NSWindow UIViewController)≠)NSViewController UIView)≠)NSView UIControl)≠)NSControl #Pragma'Conference'2014
DIFFERENCES #Pragma'Conference'2014
VIEW%SYSTEM #Pragma'Conference'2014
#Pragma'Conference'2014
WINDOWS @interface MyWindowController : NSWindowController @end @implementation MyWindowController - (instancetype)init
{ return [super initWithWindowNibName:@"MyWindow"]; } @end #Pragma'Conference'2014
WINDOW&CONTROLLERS Part%of%the%responder%chain Very%similar%to%UIViewController Typically(become(very(large #Pragma'Conference'2014
UIVIEWCONTROLLER,VS., NSVIEWCONTROLLER NSViewController-gained-lots-of- UIViewController's-capabili9es-in-10.10 Part%of%the%responder%chain Nested&view&controllers #Pragma'Conference'2014
UIVIEW Vs. NSVIEW #Pragma'Conference'2014
NSVIEW AppKit&predates&Core&Anima0on&by&a&long&0me Views&on&the&Mac&are¬&layer&backed& by&default #Pragma'Conference'2014
LAYER&BACKING Best%prac*ce:% Enable'on'window's'content'view self.contentView.wantsLayer = YES; Never%touch%wantsLayer%again #Pragma'Conference'2014
LAYER&BACKING Layers'are'an'implementa.on'detail Do not touch! #Pragma'Conference'2014
You$can$modify$layer$proper1es$in$updateLayer,$ but$then$drawRect:$is$not$called$anymore. #Pragma'Conference'2014
@implementation ColoredView - (BOOL)wantsUpdateLayer { return YES; } - (void)updateLayer
{ self.layer.backgroundColor = self.backgroundColor.CGColor; } - (void)setBackgroundColor:(NSColor *)backgroundColor { _backgroundColor = backgroundColor; [self setNeedsDisplay:YES]; } @end #Pragma'Conference'2014
LAYER&HOSTING Layer&hos*ng&views&own&their&backing&layer&and& its&sub7layers You$control$those$layers$and$can$modify$them$ at$will You$cannot$use$sub,views$anymore #Pragma'Conference'2014
- (instancetype)initWithFrame:(NSRect)frame { self = [super initWithFrame:frame]; if (self) {
self.layer = [[CALayer alloc] init]; self.wantsLayer = YES; } } #Pragma'Conference'2014
EVERYTHING*IS upside down #Pragma'Conference'2014
COORDINATE*SYSTEM By#default#the#view's#origin#is#in#the# lower5le6#corner (Just as it was in math class)
Override'flipped'if'you're'ge.ng'dizzy. #Pragma'Conference'2014
THE$WEIRD$WORLD$OF NSCELL #Pragma'Conference'2014
CELLS Many%controls%are%backed%by%cells Controls(delegate(drawing(to(their(cells For$custom$controls$you'll$o.en$have$to$ subclass$both (For%example%NSButton%and%NSButtonCell) #Pragma'Conference'2014
ANIMATIONS #Pragma'Conference'2014
ANIMATIONS Anima&on(of(non*layer*backed(views(is( CPU(intensive With%layer+backed%views%the%GPU%can%help #Pragma'Conference'2014
REMEMBER? Don't Touch BACKING(LAYERS #Pragma'Conference'2014
ANIMATOR(PROXY view.animator.alphaValue = .5; view.animator.frame = NSZeroRect; #Pragma'Conference'2014
ANIMATION'CONTEXT [NSAnimationContext runAnimationGroup:^(NSAnimationContext *ctx){ ctx.duration = 1; ctx.timingFunction = [CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseIn]; view.animator.alphaValue = .5; } completionHandler:^{ // ... }]; #Pragma'Conference'2014
ANIMATION'CONTEXT [NSAnimationContext runAnimationGroup:^(NSAnimationContext *ctx){ ctx.allowsImplicitAnimations = YES; [self layoutSubtreeIfNeeded]; }
completionHandler:^{ // ... }]; #Pragma'Conference'2014
CORE%ANIMATION CAKeyframeAnimation *animation = [CAKeyframeAnimation animation]; animation.values = @[@1, @.9,
@.8, @.7, @.6]; view.animations = @{@"alphaValue": animation}; view.animator.alphaValue = .5; #Pragma'Conference'2014
LAYER&REDRAW&POLICY By#default#layers#are#redrawn#with#every#frame# of#the#anima4on self.layerContentsRedrawPolicy = NSViewLayerContentsRedrawOnSetNeedsDisplay; #Pragma'Conference'2014
IMAGES #Pragma'Conference'2014
UIIMAGE vs. NSIMAGE #Pragma'Conference'2014
IMAGE&REPRESENTATIONS One$image$is$backed$by$one$or$mul3ple$ representa3ons: NSBitmapImageRep! NSPDFImageRep! NSEPSImageRep! NSCIImageRep! ...! #Pragma'Conference'2014
IMAGE&REPRESENTATIONS The$representa+on$to$use$is$chosen$at$drawing$ +me,$matching$the$current$graphics$context$and$ drawing$dimensions #Pragma'Conference'2014
RESOLUTION*VS.*SIZE Image&representa,ons&have&three& dimension&proper,es: size,&pixelsWide,&pixelsHigh Resolu'on)is)calculated)from)the) representa'on's)size)and) pixel)dimensions #Pragma'Conference'2014
CONVENIENCE'DRAWING It's%very%easy%to%draw%an%image: [NSImage imageWithSize:(NSSize)size flipped:(BOOL)drawingHandlerShouldBeCalledWithFlippedContext drawingHandler:^BOOL (NSRect dstRect) { //
your drawing commands here... }]; #Pragma'Conference'2014
COLORS #Pragma'Conference'2014
COLORS The$Mac$supports$fully$ color1calibrated$workflows Specify(a(colorspace(when(instan2a2ng( color(objects #Pragma'Conference'2014
COLORS #Pragma'Conference'2014
COLORS +[NSColor colorWithSRGBRed: green: blue: alpha:] #Pragma'Conference'2014
SANDBOXING #Pragma'Conference'2014
SANDBOXING Sandboxing*is*a*good*thing*conceptually Sandboxing*on*the*Mac*doesn't*work* for*everyone Feels%more%restric,ve%on%OS%X,% because%there%were%no%restric,ons%before #Pragma'Conference'2014
CONSIDER)IT)early)IN)THE DEVELOPMENT)PROCESS! #Pragma'Conference'2014
SUPERPOWERS #Pragma'Conference'2014
MAC$ONLY Inter&process+communica0on Scrip&ng Plugins Daemons ... #Pragma'Conference'2014
OBJC.IO/ISSUE+14 #Pragma'Conference'2014
THANK&YOU! @FLORIANKUGLER OBJC.IO'[/BOOKS] DECKSETAPP.COM #Pragma'Conference'2014
FURTHER'READING AppKit&for&UIKit&developers&on&objc.io objc.io&issue Mike&Ash&on&windows&and&window&controllers Adding&view&controllers&to&the&responder&chain&pre&10.10 IntroducAon&to&View&Programming&Guide&for&Cocoa Cocoa&Drawing&Guide WWDC:&Layer&Backed&Views:&AppKit&+&Core&AnimaAon WWDC:&OpAmizing&Drawing&and&Scrolling WWDC:&Best&PracAces&for&Cocoa&AnimaAon
Layer&properAes&you're¬&supposed&to&touch Jonathan&Willing's&guide&to&OS&X&animaAons IntroducAon&to&Color&Programming&Topics IntroducAon&to&Color&Management Sandboxing&Guides #Pragma'Conference'2014