Разработка приложений для iPhone, iPad и iPod touch.iOS SDK [Марк]...
-
Upload
ovidiu-tuvrila -
Category
Documents
-
view
130 -
download
2
Transcript of Разработка приложений для iPhone, iPad и iPod touch.iOS SDK [Марк]...
-
18 19 19
20
1. 21 21 23 24 iOS? 25
25 26 26 26 26 27 27
27 28 28 ? 30 ? 30
2. 31 Xcode 31
Xcode Project 34 Interface Builder 37
-
7
nib-? 38 View 39 41
43 45 47
3. 49 50C 51C 51
52 53 54 57
62 MainWindow.xib 64 Button_FunViewController.xib 65
Interface Builder 65 67 70
70
4. 71, 71 73 74 75
75 76 77 80 84 84
84 Done 85 86
-
8
89 89 89 91 92
, 92
92 , 95 96 97
98, 98 99 101
102 viewDidLoad 103 104
104 105
5. 107 108 109
109 111 Size Inspector 113 114
115 117 117
119 120 121
-
9
122 123
125
6. 127 127 131
132 134
134 nib- 135 137 SwitchViewController.h 138 139 141 142 146 149
152
7. 153 Pickers 153 156 157
157 158 MainWindow.xib 160 163
164 166
167 167 168
172 173 173 174
-
10
177 183
183 184 185 186 spin 188 viewDidLoad 189 191 Audio Toolbox Framework 196
197
8. 199 200
200 201
202 202 203 206 208 210 210 213
214 214 215 216
UitableViewCell nib- 219 220 Interface Builder 221 223
224 224 225 225
-
11
229 230
230 231 233
234 235
allNames 239 239 viewDidLoad 241 242 242 242 245
248
9. 249
249 250 250
Nav 252 252 Nav 256 : 264 : 272 : 277 : 284 : 290 : 296 ... 317
319
10. iPad 321 321
SplitView 323 xib- 325
-
12
327 334
338 345
11. Settings 347
347 AppSettings 349
350 352 364 369 373
, 376
12. 377 377
Documents 378 tmp 379
379 380 380
380 381 Persistence 382 387 NSCoding 388 NSCopying 389 390 Archiving 391
iOS SQLite3 395 396 397 SQLite3 399
Core Data 406 407
-
13
Core Data 411 420
13. Grand Central Dispatch 421
Grand Central Dispatch 421 SLOWWORKER 422 425 427 GCD 427
428 SlowWorker 429
435 436 437 State Lab 439 440 442 443 448
GCD 458
14. Quartz OpenGL 459 459 , Quartz 460
Quartz 460 461 462 465 : , 465 Quartz 2D: , 466
quatzfun 467 467 Quartz 2D 477 QuartzFun 482
GLFUN 486 GLFUN 487
-
14
OpenGL ES 489 GLFun 496
497
15. , 499 500 501
501 , 502 503 503 503
504 TouchExplorer 505 TouchExplorer 508
509 Swipes 510 512 514
515 521 524
524 528
, ! 529
16. Core Location 531
532 532 533 533 534
534 CCLocation 534 536
-
15
Core Location 537 541 542
, 543
17. 545 545 547
Core Motion 547 548 553 556
557 558 559
564 564 566 569
572
18. 573 UIImagePickerController 573 575 577
579 579
! 584
19. 585 585 587
587 588
iOS 588 LocalizeMe 589 LocalizeMe 593
-
16
nib- 594 597 599 601
, 603
20. 605 605
, Apple 606 606 607- 607 608 609 610
610
611
-
107 5.
5
iPhone iPad, , - iOS, . Apple -. , , ( ), ( ) , . , (autorotation), - iOS Mobile Safari (.5.1).
.5.1. iOS, Mobile Safari , .
-
108 5.
. - .
.
iPhone . , , . iPad, Apple -, ( , - ) .
iPad, Apple, . , . , - Mail Notes , (, - ) , - .
, , . , Apple , - iOS UIKit, - iOS .
, , - , , ( , ). - , -, .
iPhone iPod touch , 320 480 . iPad 768 1024 . - (status bar), , , 20 . 20 , - (..5.1). , .
, , : 480 - 320 (iPhone iPod touch) 1024 768 (iPad). , , , ( ), 20.
. : Retina iPhone 4 iPod touch? Retina Apple, - iPhone4 iPod touch. : 640960 . , Appl, ( ). Retina , , Cocoa Touch, iPhone iPod, 320480. , iOS . 14.
-
109 5.
iOS. , , , - .
. , . - .
(autosize) , . - , - iOS, , - . Cocoa MacOSX, , , Cocoa , , .
, . - . . . - Interface Builder , . UIViewController .
.
Xcode Autosize. , - iPhone. - Interface Builder, iOS, . - .
Xcode, Classes
AutoSizeViewController.m. , , - shouldAutorotateToInterfaceOrientation:. - . ... /* // , , // . - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { // YES
-
110 5.
return (interfaceOrientation == UIInterfaceOrientationPortrait); } */ ...
, , . , - iOS, -.
UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight iPhone -
: UIInterfaceOrientationPortrait. iPad, shouldAutorotateToInterfaceOrientation: . YES, Apple , iPad - .
, iOS, , . interfaceOrientation , , YES, NO, , -, . - - , - , .
, iPhone ? , UIInterfaceOrientationPortrait, UIInterfaceOrientationPortraitUpsideDown, UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientation, Code Sense, Xcode.
, , , , Xcode - , . Code Sense . , , , -. , UIInterfaceOrientation ( UIInterf), , , . ( - Xcode .) , . .
, , interfaceOrientation YES , UIInterfaceOrientationPortrait, , -, .
-
111 5.
, , YES . - (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation { return YES; }
, , , iPad, iPhone.
, , - interfaceOrientation YES , , NO , . , , , : - (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); }
shouldAutorotateToInterfaceOrientation:, . , Apple UIInterfaceOrientationPortraitUpsideDown iPhone, , , , - . iPad, - , .
. nib- Interface Builder.
Xcode, Resources AutosizeViewController.xib, Interface Builder. . , , - , - Interface Builder.
, , , .5.2. . 1 6.
, , , .
-
112 5.
.5.2.
-, nib-. Xcode, . iPhone,
, iPhone (. 5.3).
.5.3. , ? 5 6?
, , . . , , , , . .
Interface Builder. , .
-
113 5.
Size Inspector
, , (size inspector), - .5.4.
(size inspector) - (autosize atributes) . .5.5 , .
.5.4.
.5.5. Autosizing
.5.5, , , . , -, .
, , . . , .
-. , , , . , , . - , iPhone - . - .
I- , - . , -, , - .
?
-
114 5.
, , . .5.5, -, . , , - .
, , - , . , , - .
. I- ( ), , .5.6.
I- - , - , .5.7.
.5.6. , -
,
.5.7.
, , - . , . , , - .
. , . , .5.6, , , .
, .5.8, nib-, - Xcode, . , iPhone,
, (. .5.8). , . - .
-
115 5.
.5.8.
.5.9.,
, , , , . , -, ? - , . , , , - .
, . - , . . , .
Interface Builder, ,
, W ( ) H ( ) 125. - 125 . , , , .5.10.
-
116 5.
.5.10.
nib-, Xcode . , , ? , .5.8, , , . - , .5.11, , 125 .
.5.11. , , .
, , , - , . , - . .
-
117 5.
, , -
, . , , . AutosizeViewController.h : #import
@interface AutosizeViewController : UIViewController { UIButton *button1; UIButton *button2; UIButton *button3; UIButton *button4; UIButton *button5; UIButton *button6; } @property (nonatomic, retain) IBOutlet UIButton *button1; @property (nonatomic, retain) IBOutlet UIButton *button2; @property (nonatomic, retain) IBOutlet UIButton *button3; @property (nonatomic, retain) IBOutlet UIButton *button4; @property (nonatomic, retain) IBOutlet UIButton *button5; @property (nonatomic, retain) IBOutlet UIButton *button6; @end
Interface Builder. - -. , nib- Xcode.
. . - , Interface Builder . - nib-, . . , , iOS, , , Interface Builder, . nib- Interface Builder, , , Interface Builder . , - . .
, -
willAnimateRotationToInterfaceOrientation:duration: in AutosizeViewController.m. , .
, , , . #import "AutosizeViewController.h"
@implementation AutosizeViewController @synthesize button1; @synthesize button2;
-
118 5.
@synthesize button3; @synthesize button4; @synthesize button5; @synthesize button6; - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration { if (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { button1.frame = CGRectMake(20, 20, 125, 125); button2.frame = CGRectMake(175, 20, 125, 125); button3.frame = CGRectMake(20, 168, 125, 125); button4.frame = CGRectMake(175, 168, 125, 125); button5.frame = CGRectMake(20, 315, 125, 125); button6.frame = CGRectMake(175, 315, 125, 125); } else { button1.frame = CGRectMake(20, 20, 125, 125); button2.frame = CGRectMake(20, 155, 125, 125); button3.frame = CGRectMake(177, 20, 125, 125); button4.frame = CGRectMake(177, 155, 125, 125); button5.frame = CGRectMake(328, 20, 125, 125); button6.frame = CGRectMake(328, 155, 125, 125); } } - (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown); }
- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // , // // , // } - (void)viewDidUnload { // . // , myOutlet = nil; self.button1 = nil; self.button2 = nil; self.button3 = nil; self.button4 = nil; self.button5 = nil; self.button6 = nil; [super viewDidUnload]; }
- (void)dealloc {
-
119 5.
[button1 release]; [button2 release]; [button3 release]; [button4 release]; [button5 release]; [button6 release]; [super dealloc]; }
, , , frame, CGRect. CGRectMake() Apple, - CGRect, x y, .
. CGRect() CG. , Core Graphics . , Core Graphics , . iOS SDK Core Graphics Xcode, . , Core Graphics - Xcode iPhone iPad.
. , -. , .
, ,
, . , -, .
, . , . , - , - . , , - . . , -. , - , .
Xcode, , ( ). Swap. , - (.5.12).
, - . (.5.13), , .
-
120 5.
.5.12. Swap
.5.13., .
. - . , , , , , .
, -
, :
-
121 5.
. , .
! , -? , , , , sender? -, .
. , , ? , , , . - , , , , .
, , - . , . - , -, , , UIView.
, , - , , - buttonPressed: .
, Interface Builder
SwapViewController.h: #import
#defi ne degreesToRadians(x) (M_PI * (x) / 180.0) @interface SwapViewController : UIViewController { UIView *landscape; UIView *portrait;
// Foo UIButton *landscapeFooButton; UIButton *portraitFooButton;
// Bar UIButton *landscapeBarButton; UIButton *portraitBarButton; } @property (nonatomic, retain) IBOutlet UIView *landscape; @property (nonatomic, retain) IBOutlet UIView *portrait; @property (nonatomic, retain) IBOutlet UIButton *landscapeFooButton; @property (nonatomic, retain) IBOutlet UIButton *portraitFooButton; @property (nonatomic, retain) IBOutlet UIButton *landscapeBarButton; @property (nonatomic, retain) IBOutlet UIButton *portraitBarButton; - (IBAction)buttonPressed:(id)sender; @end
-
122 5.
, - : #defi ne degreesToRadians(x) (M_PI * (x) / 180.0)
, - . , , , . .
, Interface Builder . SwapViewController.xib , Interface Builder.
, Interface Builder,
. nib-. - , , . , , .
, . . - . , - , -.
nib-, - , , -, . , . , -. , . , - , portrait. - landscape.
, view, , .
, . 320 460 . , 480 300 , , - . - . -. 125 125 . , .
- landscapeFooButton; ,
landscapeBarButton. , . , -
-
123 5.
, buttonPressed:. , buttonPressed:, . .
, -. . 125 . . .
portraitFooButton. - portraitBarButton.
buttonPressed:. .
nib- Xcode.
. , -
, . , , SwapViewController.m.
. -. - , .
#import "SwapViewController.h"
@implementation SwapViewController @synthesize landscape; @synthesize portrait; @synthesize landscapeFooButton; @synthesize portraitFooButton; @synthesize landscapeBarButton; @synthesize portraitBarButton;
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation duration:(NSTimeInterval)duration { if (interfaceOrientation == UIInterfaceOrientationPortrait) { self.view = self.portrait; self.view.transform = CGAffi neTransformIdentity; self.view.transform = CGAffi neTransformMakeRotation(degreesToRadians(0)); self.view.bounds = CGRectMake(0.0, 0.0, 320.0, 460.0); } else if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) { self.view = self.landscape; self.view.transform = CGAffi neTransformIdentity; self.view.transform = CGAffi neTransformMakeRotation(degreesToRadians(-90));
-
124 5.
self.view.bounds = CGRectMake(0.0, 0.0, 480.0, 300.0); } else if (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) { self.view = self.portrait; self.view.transform = CGAffi neTransformIdentity; self.view.transform = CGAffi neTransformMakeRotation(degreesToRadians(180)); self.view.bounds = CGRectMake(0.0, 0.0, 320.0, 460.0); } else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) { self.view = self.landscape; self.view.transform = CGAffi neTransformIdentity; self.view.transform = CGAffi neTransformMakeRotation(degreesToRadians(90)); self.view.bounds = CGRectMake(0.0, 0.0, 480.0, 300.0); } }
- (IBAction)buttonPressed:(id)sender { if (sender == portraitFooButton || sender == landscapeFooButton) { portraitFooButton.hidden = YES; landscapeFooButton.hidden = YES; } else { portraitBarButton.hidden = YES; landscapeBarButton.hidden = YES; } }
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation { return YES; }
- (void)didReceiveMemoryWarning { // , [super didReceiveMemoryWarning]; // , , }
- (void)viewDidUnload { // . // , self.myOutlet = nil; self.landscape = nil; self.portrait = nil; self.landscapeFooButton = nil; self.portraitFooButton = nil; self.landscapeBarButton = nil; self.portraitBarButton = nil; [super viewDidUnload]; }
-
125 5.
- (void)dealloc { [landscape release]; [portrait release]; [landscapeFooButton release]; [portraitFooButton release]; [landscapeBarButton release]; [portraitBarButton release]; [super dealloc]; } @end
willAnimateRotationToInterfaceOrientation:duration:. -, , . , , .
, -, , . CGAffi neTransformMakeRotation, - Core Graphics, (rotation transformation). , - . iOS . - , , - . willAnimateRotationToInterfaceOrientation:duration: , -. , .
buttonPressed:. . , , , - .
, , . shouldAutorotateToInterfaceOrientation: YES, iPhone, , , dealloc, .
.
. , . .
-
. , , , - iOS. , , - , .
-
126 5.
- nib-. -. , , , , , . iOS, Mail Contacts, , , , 6.
-
0 1-412345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667.067.167.268697071727374757677787980818283848586
561234567891011121314151617181920212223242526
7Binder1123456789101112131415161718192021222324252627282930313233343536373839404142434445
81234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
9137
10-1112345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
12-1312345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
14123456789101112131415161718192021222324252627282930313233343536373839
15-20123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
Binder1.pdf12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970