89
iOS 7 SDKľƩŀ 彼得潘 IJť ŭd´·IJ Ƒ: AppŢ®ƫƦ2Ǧ - iPhone . iPad ĹÂƺȄ¤džȇŢ£ 2012 ¨ª ŎDzƇȀ Top 6 AppŢ®ƫƦ2Ǧ

iOS 7 SDK特訓班

Embed Size (px)

DESCRIPTION

agenda: iOS 7 SDK簡介 Xcode 5新功能簡介 更進步的Objective-C和Foundation framework iOS 6 App改版iOS 7 (UI調整) 動態文字大小 酷炫動畫1: Motion Effects (3D) 酷炫動畫2: UIKit Dynamics (2D)

Citation preview

Page 1: iOS 7 SDK特訓班

iOS 7 SDKľƩŀ彼得潘

• IJ�ť

• ŭd´·IJ

• Ƒ�: AppŢ®ƫƦ2Ǧ -ȍȍ iPhone . iPad

• ĹÂƺȄ¤džȇ�Ţ£

2012¨ªŎ�DzƇȀ Top 6

AppŢ®ƫƦ2Ǧ

Page 2: iOS 7 SDK特訓班

APPǨŌ

Macå�

�ę

ŔǪð�ƽĮ http://www.facebook.com/iphone.peterpan

http://deeploveapple.blogspot.tw

[email protected]

http://apppeterpan.blogspot.tw

FBűŵv

blog

ôwiki

ƨƵOhttp://peterpan.uservoice.com

http://deeploveiossdk.tumblr.comƎôwiki

email

Page 3: iOS 7 SDK特訓班

agenda

• iOS 7 SDKŰ�

• Xcode 5öHƅŰ�

• āǑĜŏObjective-CjFoundation framework

• iOS 6 AppìļiOS 7 (UIƳò)

• KÄô���• ǡijKʼn1: Motion Effects (3D)

• ǡijKʼn2: UIKit Dynamics (2D)

iOS 7 SDK�

Page 4: iOS 7 SDK特訓班

ľƊ• 4öUI

• āǡijŏKʼn• ā°�ŏƄÿ��• ā°�ŏô�ȕł• ǟNJdeviceǩįǍ

• 4öǒȑ¯æ• ǒȑǖØn• ,ĭºūjŗŘ• ƦĜn

• deviceǩ<�ėĎ

• AppǩŏƃǷ.Lj

• JavaScriptȕł

• iBeacon

• Machine Readable Code Detection

• ā°�ŏApple Map

• IBSafari Reading list

• ǨZƲư

4öUI• §ǶNŏUI0�

• ĵǝčŏButtonƫƦ

• wnav barȁŞsearch bar

• blurred background ( njüĞĿŃïċ)

• image rendering mode (AppìļiOS 7 )

• tint color (AppìļiOS 7 )

• full screenƫƦȏ njüstatus bar & ǥȈŏnavigation bar (AppìļiOS 7 )

Page 5: iOS 7 SDK特訓班

§ǶNŏUI0�

ĵǝčŏbutton

wnav barȁŞsearch barUISearchBar *searchBar = [[UISearchBar alloc] init];

searchController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self]; searchController.searchResultsDataSource = self;searchController.searchResultsDelegate = self;searchController.delegate = self;

searchController.displaysSearchBarInNavigationBar = YES;searchController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStylePlain target:self action:@selector(close:)];

UISearchDisplayController.h@property (nonatomic, assign) BOOL displaysSearchBarInNavigationBar;

dzßǠUINavigationControllerȏ�ƅ\ǵUINavigationBar

Page 6: iOS 7 SDK特訓班

blurred background(njüĞĿŃïċ)

https://developer.apple.com/downloads/index.action

UIImage+ImageEffects- (UIImage *)applyBlurWithRadius:(CGFloat)blurRadius tintColor:(UIColor *)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage *)maskImage;

UIToolbarƛ�ĞĿŃ- (void)viewDidLoad{ [super viewDidLoad];! UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 20, 320, 320)]; [self.view addSubview:scrollView]; scrollView.contentSize = CGSizeMake(320, 1000); UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 1000)]; imageView.image = [UIImage imageNamed:@"cute.jpg"]; [scrollView addSubview:imageView]; UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 20, 320, 44)]; [self.view addSubview:toolBar];}

Page 7: iOS 7 SDK特訓班

UIToolbarƛ�ĞĿŃ

UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 20, 320, 44)];[self.view addSubview:toolBar];

toolBar.barTintColor = [UIColor blueColor];

ǡijKʼn

• ƈƥview controllerlj|Kʼn

• Collection ViewŏKʼn

• interactive transition

• Motion Effects (��ıŸ )

• UIKit Dynamics (��ıŸ )

Page 8: iOS 7 SDK特訓班

ƈƥview controllerlj|Kʼn

http://www.doubleencore.com/2013/09/ios-7-custom-transitions

http://www.appdesignvault.com/custom-transition-ios-7

http://blog.bignerdranch.com/3871-golden-opportunity-custom-transitions/

UIViewControllerAnimatedTransitioning protocol

Collection ViewÔļKʼn

WWDC 2013 Sample: iOS_CollectionViewTransition

ex: ķĻApp¸Years ViewBCollectionsŏzoom inKʼnhttps://developer.apple.com/downloads/index.action?name=WWDC%202013

Page 9: iOS 7 SDK特訓班

interactive transition

• AņÊLØCcontrollerʼnǶŏljÛ

• ex: e_scrolloF�ǹȏe WÁ+wS�ǹǶ

UIViewControllerInteractiveTransitioning

Multitasking Enhancements

• wƄÿ�LJÈ�.ƽõ(Background Fetch)ƫ��ĆāöŏȒǩ

• ǗŪÙã ( Remote Notification )ëBÙãȒÐXƽõȏÐBƽƧ¶9ȁŞÙãAņsilent pushƣŌƽõāö(�ăȁŞÙãƧÀ)

Page 10: iOS 7 SDK特訓班

wƄÿāöAppʼnǶ

Remote Notification��

Page 11: iOS 7 SDK特訓班

Text Kit

Letterpress ( :ļQD)

ģąLetterpress ąLetterpress

Page 12: iOS 7 SDK特訓班

letterpress��UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];label.font = [UIFont systemFontOfSize:150];label.textAlignment = NSTextAlignmentCenter;NSDictionary *attrDic = @{NSForegroundColorAttributeName : [UIColor colorWithRed:0 green:0 blue:1 alpha:0.5], NSTextEffectAttributeName : NSTextEffectLetterpressStyle};NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@"´·" attributes:attrDic];label.attributedText = attrString;[self.view addSubview:label];

NSAttributedString.hUIKIT_EXTERN NSString *const NSTextEffectLetterpressStyle NS_AVAILABLE_IOS(7_0);

Exclusion paths

şȊ$"Ĉō ŠȂƮ

Page 13: iOS 7 SDK特訓班

Exclusion paths��UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 40, 320, 400)];textView.backgroundColor = [UIColor clearColor];textView.textColor = [UIColor whiteColor];textView.text = @"ŠȂīȏŠĄüȏƏƐƂǜñȏ�ȉĐ¹ȅȎŔ¿Ŕƞř�úȐěȒě�ǰĴÂȎ2ÇŔ¿ǦȏřÇŔ¿ƍȏǥŔ¿6ǥŔÅȏŚŔ¿6ĵŨđȏûř�ěų�»ȏǜ�Ŋ>�ŔƶȎ ";textView.font = [UIFont systemFontOfSize:28];

UIBezierPath *path = [UIBezierPath bezierPath];[path moveToPoint:CGPointMake(10.0, 40.0)];[path addLineToPoint:CGPointMake(110.0, 140.0)];[path addLineToPoint:CGPointMake(210, 40)];[path closePath];textView.textContainer.exclusionPaths = @[path]; [self.view addSubview:textView];

NSTextContainer.h@property(copy, NS_NONATOMIC_IOSONLY) NSArray *exclusionPaths;

Text attachments

Page 14: iOS 7 SDK特訓班

Text attachments��UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 40, 320, 400)];textView.backgroundColor = [UIColor clearColor];

NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"ŠȂīȏŠĄüȏƏƐƂǜñȏ�ȉĐ¹ȅȎŔ¿Ŕƞř�úȐě������������Ȓě�ǰĴÂȎ"];NSTextAttachment *attachment = [[NSTextAttachment alloc] init];attachment.image = [UIImage imageNamed:@"shoppingIcon.png"];[str appendAttributedString:[NSAttributedString attributedStringWithAttachment:attachment]];[str appendAttributedString:[[NSMutableAttributedString alloc] initWithString:@"2ÇŔ¿ǦȏřÇŔ¿ƍȏǥŔ¿6ǥŔÅȏŚŔ¿6ĵŨđȏûř���������ěų�»ȏǜ�Ŋ>�ŔƶȎ"]];textView.attributedText = str; [self.view addSubview:textView];

NSTextAttachment.h@interface NSAttributedString (NSAttributedStringAttachmentConveniences)// A convenience method for creating an attributed string containing attachment using NSAttachmentCharacter as the base character.+ (NSAttributedString *)attributedStringWithAttachment:(NSTextAttachment *)attachment NS_AVAILABLE_IOS(7_0);@end

dynamic text size

ţ¶ÜĀ

Page 15: iOS 7 SDK特訓班

AirDropavailable on iPhone 5, iPad (4th generation), iPad mini, and iPod touch (5th generation) ��

requires an iCloud account

.Lj: WifiÈBluetooth

AirDrop��• AņUIActivityViewController

• ShareŏǺŒ

• NSString & NSAttributedString ( Notes.app×ë)

• UIImage & AVAsset (Photos.app×ë)

• NSURL

• Safari.app×ë

• ľ�App×ë

Page 16: iOS 7 SDK特訓班

Machine Readable Code Detection

support barcode

• QR code

• Aztec

• EAN13

• EAN8

• UPC-E

• PDF417

• Code 93

• Code 39

• Code 39 mod 43

AVCaptureMetadataOutput

Page 17: iOS 7 SDK特訓班

SSReadingListIBSafari Reading list

NSURL *url = [NSURL URLWithString:@"https:/ /www.facebook.com/iphone.peterpan"];[[SSReadingList defaultReadingList] addReadingListItemWithURL:url title:@"´·IJ" previewText:@"Ãŋ�=ĴƔċ" error:nil];

,ĭºūjŗŘ

• CIDetectorSmile

• CIDetectorEyeBlink

Page 18: iOS 7 SDK特訓班

Multipeer Connectivity • ǟNJdeviceǩŏįǍj.Ljƽõ

• ǐ×ø®:infrastructure Wi-Fi networkspeer-to-peer Wi-FiBluetooth

Multipeer Connectivity

Page 19: iOS 7 SDK特訓班

Inter-App Audio

• Appǩ.NjMIDIÒ�

• AppǩŏǷƧ.Lj

iBeaconbluetooth

,ĭǂǯ

ŌNjbeacon : iPhoneÈŬ�øśȇ

CLBeaconRegion

Page 20: iOS 7 SDK特訓班

Map Kit

MKOverlayRenderer

4öŏoverlay

Page 21: iOS 7 SDK特訓班

MKOverlayRenderer

Direction

Page 22: iOS 7 SDK特訓班

AVSpeechSynthesisAVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc] init];AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@"´·IJ"];[synthesizer speakUtterance:utterance];

Ǩ� Zŏư�ƹ

AVSpeechSynthesizer¦Ç'Ʋ;Zg

AVSpeechSynthesizer: �rƱƤǕ�

ƦĜn

• M7

• 5s��Ėnsupport

• CMStepCounter

• typedef void (^CMStepUpdateHandler)(NSInteger numberOfSteps, NSDate *timestamp, NSError *error);

Page 23: iOS 7 SDK特訓班

Sprite Kit

• �ņ�ŽOpenGL ES

• �ņ(JŬ�ølibraryȏ��Cocos 2D

• ā�ýxǨŌ2Dǒȑ

Game Controller

ǐ×: œ×ǐ×ÈþnjǔBluetooth

Page 24: iOS 7 SDK特訓班

Game Controller

Game Controller

Page 25: iOS 7 SDK特訓班

JavaScriptCore

• ø#¸objective-c{ƖjavascriptŢ®ŝ

• ø#¸javascript{Ɩobjective-cŢ®ŝ

Xcode 5öHƅŰ�

Page 26: iOS 7 SDK特訓班

Xcode 5

• āďŏUI�Ƕ

• āďŏïƅ

• Asset Catalogs

• Image Slicing

• āø#ŏļćůł

• āø#ŏ¥ƕůłjAppMƚĉõůł

• Interface Builder Preview

• support 64 bit iOS (iPhone 5s)

• ŇĦƢƈKNŅńô�Ʋü

• App Capabilityůł

• ïƅĘƠ�8Debug Gauges

• āø#ŏm0ĭƯXCTest

• Continuous Integration

• āø#ŏAutolayout

• Quick Look

• āďŏô�ƲüǹǶ

�ƚXcode• OS X Mavericks3­ȏ�ņ9[~�ƚ

Page 27: iOS 7 SDK特訓班

öŏtemplateę�ƫ�

Asset Catalogs &Image Slicing

• ůłuĻŏ°��8• �ņ9Ǚ�ĸ�ŏėdƟ�

ex: @2x, ~ipad

• �ņ9¸Ţ®?÷ÖņŏuĻ• ƫ�App IconȒ���Ų

Page 28: iOS 7 SDK特訓班

āø#ŏļćůłĘƠŒFbranchȏ=Ûbranchāø#

Debug Gauges

Page 29: iOS 7 SDK特訓班

āø#ŏ¥ƕůłjAppMƚĉõůł

App Capability Management

Page 30: iOS 7 SDK特訓班

Quick Look debug

Preview

Page 31: iOS 7 SDK特訓班

Preview

ƈKŅńĦƢ/** sing a song @code ViewController controller = [ViewController alloc] init]; [controller singSong:@"Ŭ89Ǥ"]; @endcode @see http://www.apple.com for more info @param song the song to sing @return YES if song name lenght > 3*/-(BOOL)singSong:(NSString*)song{ if (song.length > 3) { return YES; } else { return NO; }}

Page 32: iOS 7 SDK特訓班

IBŏauto layout• IB�9ƈKI�constraint

• ā�ņŏö}constraintƫƦ

m0ĭƯXCTest

Page 33: iOS 7 SDK特訓班

Continuous Integration

• ƈKbuildȏƈKĭƯȏƈKMƚApp

• ^ǁwsimulatorÈǐ×ŏ�Ė

• dzßǠOS X Mavericks Server

• ƣŌø®• ÊK• on commit

• periodically

Continuous Integration

Page 34: iOS 7 SDK特訓班

āǑĜŏObjective-Cj

Foundation framework

Objective-CjFoundation framework

• module

• instancetype

• NSArray

Page 35: iOS 7 SDK特訓班

module

• ƈKǐŴSDK3­ŏframework

• ā¾ŏŷƷȒǩ• öŏimportƱĥ

ƈKǐŴ3­ŏframework

Page 36: iOS 7 SDK特訓班

ĵmoduleļć

Ƣĥ: ÊKI2MapKit.framework

moduleļć

ƈKǐŴ !

Page 37: iOS 7 SDK特訓班

@import

• @import QuartzCore;

• @import QuartzCore.CoreAnimation;

• #import ƈKƙljÛĴ@importex:(1) #import <UIKit/UIKit.h> @import UIKit;(2) #import <iAd/ADBannerView.h> @import iAd.ADBannerView;

• ƈƥŏȀ@�þmoduleȏǜþƜņ#import

enable modules

Page 38: iOS 7 SDK特訓班

instancetype

idkǾ

NSArray.h+ (id)array;

NSDictionary *dic = [NSArray array];

Page 39: iOS 7 SDK特訓班

instancetype

NSArray.h+ (instancetype)array;

\ƅņwreturn type

¼ǻo.ěȀ@Ľ�

�XarrayŏŬ�&jö�&

NSArray.h- (id)firstObject NS_AVAILABLE(10_6, 4_0);- (id)lastObject;

firstObjectwiOS 7Ë5Ǩ

NSArray *array = [[NSArray alloc] init]; NSLog(@"array %@", array[0]);

NSArray *array = [[NSArray alloc] init]; NSLog(@"array %@", [array firstObject]); o.nil

Page 40: iOS 7 SDK特訓班

iOS 6 AppìļiOS 7

�ĕŢ®ȏ�cĕ®

iOS 7 iOS 6

Page 41: iOS 7 SDK特訓班

iOS 6 AppìļiOS 7• App IconjǨǽʼnǶ

• Asset CatalogsjImage Slicing

• tint color

• ?÷iOSļć

• full screenƫƦȏnjüstatus bar & ǥȈŏĞĿŃnavigation bar

• image render mode

• interactivePopGestureRecognizer

• keyboard , picker & alert view

App Icon size�� App Icon��(pixel)iPhone 57 * 57

iPhone Retina 114 * 114iPad (iPad mini) 72 * 72

iPad Retina 144 * 144iPhone Retina iOS 7 120 * 120

iPad (iPad mini) iOS 7 76 * 76iPad Retina iOS 7 152 * 152

Page 42: iOS 7 SDK特訓班

iOS 7êÞŏĖz

�4Retina

ŊAppĴiPhone AppȏƁ�\êÞiOS 7��-> uĻ\dzÚ retinaļć

Ǩ�ʼnǶsize�� Launch Image��(pixel)

iPhone 3.5b 320 * 480

iPhone Retina 3.5b 640 * 960

iPhone Retina 4b 640 * 1136

iPad (iPad mini) 768 * 1024 1024 * 768

iPad Retina 1536 * 2048 2048 * 1536

full screenȏ�9ÌǬstatus bar

Page 43: iOS 7 SDK特訓班

App Icon

Ɖ�Ďƪ·1ö}asset catalogsȏĶ¶9ȌǚUse Asset Catalog

ö}asset catalogs

Page 44: iOS 7 SDK特訓班

Fµasset catalogsƫ�ǹǶ

image.xcassetsŏAppIcon

Page 45: iOS 7 SDK特訓班

ƫ��ciOSļćŏAppIconattributes inspectorps: ƪ·1ƳòDevelopment Target

• \support pngČ®

• 7�Č®ŏuĻǜþ·ÖņƉøĥ

• I2uĻ

Asset Catalogs

andy.png tony.png

self.imageView.image = [UIImage imageNamed:@"handsome"];

Page 46: iOS 7 SDK特訓班

Asset Catalogs

andy.png tony.png chilam.png tai.pnglin.png

Image Slicing

Page 47: iOS 7 SDK特訓班

tint color

tint color• ^�ȌǚŏUI0�

• activeŏUI0�ȏ��tab

• Ģ�UI0�ŏǿƊ (ex: UIButtonŏô�ǿƊ)

• Ƭ�button�ô�ƘŞ

Page 48: iOS 7 SDK特訓班

UIViewŏtintColor property

• default: blue

• tintColoro.):1. ąƫ�2. ĵƫ�ȏ¸superview���µ�Íȏo.Ŭ �&ÍBąƫ�tintColorŏsuperviewÉƫ� ŏǿƊ3. superviewŐĵƫ�ȏo.ǼƫŏtintColorǿƊ

• AppƫƦ1. �cUI0�ƫ��cŏtint color2. Ģ��&Appŏ�ƊȏÉą0�Öņc�&tint color

UIView.h@property(nonatomic,retain) UIColor *tintColor NS_AVAILABLE_IOS(7_0);

Ŋviewƈ¢ĵƫ�ȒȏsuperviewĢ� �ŏtintColor

ƫ�Appŏtint color

• ƫ�windowŏtintColor

• ¸storyboardƫ�global tint

Page 49: iOS 7 SDK特訓班

ƫ�tint color

self.view.tintColor = [UIColor orangeColor];

iOS 6 Crash

tintColor propertywiOS 7ËŁDŽ

?÷iOSļć if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {

} else { }

NSObjCRuntime.h#define NSFoundationVersionNumber_iPhoneOS_2_0!678.24#define NSFoundationVersionNumber_iPhoneOS_2_1 678.26#define NSFoundationVersionNumber_iPhoneOS_2_2 678.29#define NSFoundationVersionNumber_iPhoneOS_3_0 678.47#define NSFoundationVersionNumber_iPhoneOS_3_1 678.51#define NSFoundationVersionNumber_iPhoneOS_3_2 678.60#define NSFoundationVersionNumber_iOS_4_0 751.32#define NSFoundationVersionNumber_iOS_4_1 751.37#define NSFoundationVersionNumber_iOS_4_2 751.49#define NSFoundationVersionNumber_iOS_4_3 751.49#define NSFoundationVersionNumber_iOS_5_0 881.00#define NSFoundationVersionNumber_iOS_5_1 890.10#define NSFoundationVersionNumber_iOS_6_0 993.00#define NSFoundationVersionNumber_iOS_6_1 993.00

ƉļiOSi]öļSDK: crashöļiOSi]deprecated SDK: �^Ǔ�Èdo nothing

Page 50: iOS 7 SDK特訓班

iOS 6ŏtintColor

UINavigationBar.h@property(nonatomic,retain) UIColor *tintColor;@property(nonatomic,retain) UIColor *barTintColor NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR;

wiOS 7ȏƴìņbarTintColor

full screenƫƦ

njüŏstatus bar

ǥȈŏnavigation bar

�ņʼnǶ4ǞŏŦǩ

¬�ò&ʼnǶ�ªŏcell: UITableViewStyleGrouped�9þtơƘČĕ®

Page 51: iOS 7 SDK特訓班

view controller’s view size

• wiOS 7ȏ�Ǟ<ŏÂĤȏview sizeĴfull screen

• ƹiOS 6ŏview size�þfull screen

• status bar ƫĴblack translucent

• controllerŏwantsFullScreenLayoutƫĴYES

• navigation barŏtranslucentƫĴYES

controllerʼnǶŏ¬�

ƫ�uĻq�320 * 568

Page 52: iOS 7 SDK特訓班

���íŏnav bar & tab bar

nav barƝƒcontrollerʼnǶŏ�PǞcontrollerʼnǶȈª� �PǞtab barŏȈª( 519 = 568 - 49)

Extend Edges

Page 53: iOS 7 SDK特訓班

barŏtranslucent

nva barĴtranslucentȏpěUnder Top barsŌÝ�ņtab barģątranslucentȏpěUnder Bottom bars�T�ņ

ƫ�Under Opaque Bars

Page 54: iOS 7 SDK特訓班

ÕƆbarŏĊŹ

455 = 568 - 20 - 44 -49

¸Ţ®ƫ�UIViewController.h

@property(nonatomic,assign) UIRectEdge edgesForExtendedLayout;

@property(nonatomic,assign) BOOL extendedLayoutIncludesOpaqueBars;

UIGeometry.htypedef NS_OPTIONS(NSUInteger, UIRectEdge) { UIRectEdgeNone = 0, UIRectEdgeTop = 1 << 0, UIRectEdgeLeft = 1 << 1, UIRectEdgeBottom = 1 << 2, UIRectEdgeRight = 1 << 3, UIRectEdgeAll = UIRectEdgeTop | UIRectEdgeLeft | UIRectEdgeBottom | UIRectEdgeRight};

Page 55: iOS 7 SDK特訓班

��

- (void)viewDidLoad{ [super viewDidLoad];! // Do any additional setup after loading the view, typically from a nib. self.extendedLayoutIncludesOpaqueBars = YES; self.edgesForExtendedLayout = UIRectEdgeTop | UIRectEdgeBottom;}

scroll view inset

³Ǹscroll view, table view, web view

Page 56: iOS 7 SDK特訓班

automaticallyAdjustsScrollViewInsetsUIViewController.h

@property(nonatomic,assign) BOOL automaticallyAdjustsScrollViewInsets;

UIScrollView.h@property(nonatomic) UIEdgeInsets contentInset;

UIGeometry.htypedef struct UIEdgeInsets { CGFloat top, left, bottom, right; } UIEdgeInsets;

inset {64, 0, 0, 0}content start from 64

ŊautomaticallyAdjustsScrollViewInsetsƫĴNO

uĻ�PǞƙƒ�

Page 57: iOS 7 SDK特訓班

full screen�ǀȌ«ēƳò

• iOS 6 : (0, 0)

• iOS 7:

• only status bar : (0, 20)

• status bar + nav bar: (0, 64)

topLayoutGuide & bottomLayoutGuide

topLayoutGuide�Bnav barŏ©Ǟ

Page 58: iOS 7 SDK特訓班

topLayoutGuide & bottomLayoutGuide

topLayoutGuide�Bstatus barŏ©Ǟ

topLayoutGuide & bottomLayoutGuide

- (void)viewDidLoad{ [super viewDidLoad]; UIView *blueView = [[UIView alloc] initWithFrame:CGRectZero]; blueView.backgroundColor = [UIColor blueColor]; [self.view addSubview:blueView]; blueView.translatesAutoresizingMaskIntoConstraints = NO; id topLayoutGuide = self.topLayoutGuide; NSDictionary *viewsDictionary = NSDictionaryOfVariableBindings(blueView, topLayoutGuide); [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V: [topLayoutGuide]-10-[blueView(100)]" options:0 metrics:nil views:viewsDictionary]]; [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-50-[blueView(100)]" options:0 metrics:nil views:viewsDictionary]];

}

Page 59: iOS 7 SDK特訓班

barƄÿuĻŏ¬�UIBarPositionAnyUIBarPositionBottomUIBarPositionTopUIBarPositionTopAttached

- (void)viewDidLoad{ [super viewDidLoad];! UIImage *image = [UIImage imageNamed:@"bar.png"]; UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0, 20, 320, 44)]; [navBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault]; [self.view addSubview:navBar]; navBar.delegate = self;}

- (UIBarPosition)positionForBar:(id <UIBarPositioning>)bar{ return UIBarPositionTopAttached;}

njüŏstatus bar

ĩƊƄÿ: ŕ�Bstatus bar

Page 60: iOS 7 SDK特訓班

â·DZǨƞĄüȋjōŏô�ǿƊ

ƫƦSE: !ƄÿǿƊƳòȏĪƊƄÿǠȋƊô�ȏĩƊƄÿǠōƊô�

- (UIStatusBarStyle)preferredStatusBarStyle{ return UIStatusBarStyleLightContent;}

- (UIStatusBarStyle)preferredStatusBarStyle{ return UIStatusBarStyleDefault;}

ȋ(Ǽƫ)

ō

ěmethod\ìƸm�controllerʼnǶ�ŏstatus barȏ=ÛBöŏcontrollerVoBdefaultŏȋƊ

KÄØCstatus barô�ǿƊ

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

return YES;}

status barô�ǿƊ�pcontrollerŏ=ÛƁƸK

View controller-based status bar appearance(UIViewControllerBasedStatusBarAppearance)

dzƫĴNO setStatusBarStyle:Ëƅńï

Page 61: iOS 7 SDK特訓班

hide status bar

\ąǨǽʼnǶĨ�ȏview controllerʼnǶŁDŽȒV;Ł

[[UIApplication sharedApplication] setStatusBarHidden:isHide withAnimation:UIStatusBarAnimationFade];

��ï !

hide status bar

- (BOOL)prefersStatusBarHidden{ return YES;}

controller`ƈØCƈ¢ʼnǶ�status barþfǮƓ

Page 62: iOS 7 SDK特訓班

éƆcontrollerŏǫC

[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];

9ª¹ħwork !

ƌĵ9¸Ţ®%ìȏstatus bar�ġǗDžǀ�

ĞĿŃŏnav bar

• 3�scrollȒȏ^ŕBńKŏĞĿŃïċ

• Ȉª¸44ǥªĴ64

• ƫ�nav barŏƄÿuĻȒȏƜ�ņ64 pointȈŏuĻ

Page 63: iOS 7 SDK特訓班

bar button itemUIImage *image = [UIImage imageNamed:@"foodIcon.png"];image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(showSetting:)];self.navigationItem.rightBarButtonItem = barButtonItem;

iOS 7 iOS 6uĻƙǝčMsȏǬǴņinitWithCustomView

image render modeUIImage.h

typedef NS_ENUM(NSInteger, UIImageRenderingMode) { UIImageRenderingModeAutomatic, UIImageRenderingModeAlwaysOriginal, UIImageRenderingModeAlwaysTemplate, }

UIImageRenderingModeAlwaysTemplate:�ņtint colorŏǿƊ

Page 64: iOS 7 SDK特訓班

UINavigationControllerŏöÑƗe_scrolloF�ǹ

• Ó� ǝňe_scrollȏoBF�ǹ

• ǼƫǨl

• ex: -½ǣ

• Ǫǧ:

UINavigationController.h@property(nonatomic, readonly) UIGestureRecognizer *interactivePopGestureRecognizer;

self.navigationController.interactivePopGestureRecognizer.enabled = NO;

öŏdeleteĕ®

Page 65: iOS 7 SDK特訓班

tab bar imageUITabBarItem.h

@property(nonatomic,retain) UIImage *selectedImage;

^ƫ�²ƊuĻÈǭtint colorƸNŏuĻ^ƫ�ƙȌǚtabŏuĻ

keyboardŏȋō�Ƽ

default

UITextInputTraits.h UIKeyboardAppearanceDefault UIKeyboardAppearanceDark UIKeyboardAppearanceLight

textField.keyboardAppearance = UIKeyboardAppearanceDark;

Page 66: iOS 7 SDK特訓班

keyboardĨ�UIScrollView.h

typedef NS_ENUM(NSInteger, UIScrollViewKeyboardDismissMode) { UIScrollViewKeyboardDismissModeNone, UIScrollViewKeyboardDismissModeOnDrag, UIScrollViewKeyboardDismissModeInteractive, }

scrollView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive;

UIScrollViewKeyboardDismissModeOnDrag: scrollëǤő (ex: Ɩ�ȓŏö})

UIScrollViewKeyboardDismissModeInteractive: Ó�Ǥő�Ŷµ�scroll (ex: ǍƧǣŏö})

Picker

ǼƫƄÿ�4njü

self.picker.backgroundColor = [UIColor whiteColor];

ƫƦ: UſƖ�ȓŏö}

Page 67: iOS 7 SDK特訓班

Pnjüŏpicker

UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 50, 100, 30)];textField.borderStyle = UITextBorderStyleRoundedRect;[self.view addSubview:textField]; UIDatePicker *picker = [[UIDatePicker alloc] initWithFrame: CGRectMake(0, 0, 320, 200)];textField.inputView = picker;

alert viewUIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Hello" message:nil delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil];[alertView show]; UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 50, 50)];blueView.backgroundColor = [UIColor blueColor];[alertView addSubview:blueView];

addSubviewĵï !

UIAlertView.htypedef NS_ENUM(NSInteger, UIAlertViewStyle) { UIAlertViewStyleDefault = 0, UIAlertViewStyleSecureTextInput, UIAlertViewStylePlainTextInput, UIAlertViewStyleLoginAndPasswordInput};

Page 68: iOS 7 SDK特訓班

KÄô���

ƳòText Size

Page 69: iOS 7 SDK特訓班

NJƠžƋŐĚ»ŏǍƧǣ

ƫ�Text Styles1

2

3

Page 70: iOS 7 SDK特訓班

�UIFontDescriptor.h

UIFontTextStyleHeadlineUIFontTextStyleSubheadlineUIFontTextStyleBodyUIFontTextStyleFootnoteUIFontTextStyleCaption1UIFontTextStyleCaption2

self.nameLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];

¸Ţ®ƫ�

¸ƫ�ìƸ�ȇ��

no change ?

Page 71: iOS 7 SDK特訓班

ǢölKApp

RȒāöô���-(void)updateTextSize{ self.nameLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];}

- (void)viewDidLoad{ [super viewDidLoad];! // Do any additional setup after loading the view, typically from a nib.

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateTextSize) name:UIContentSizeCategoryDidChangeNotification object:nil]; }

ǪǤ: ǢöX·ŒFǘaŏ�ȇ��

Page 72: iOS 7 SDK特訓班

ƈƥKÄ���z-(void)updateTextSize{ UIFontDescriptor *userFont = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleHeadline]; float userFontSize = [userFont pointSize]; self.nameLabel.font = [UIFont fontWithName:@"Chalkduster" size:userFontSize];}

- (void)viewDidLoad{ [super viewDidLoad]; UIFontDescriptor *userFont = [UIFontDescriptor preferredFontDescriptorWithTextStyle:UIFontTextStyleHeadline]; float userFontSize = [userFont pointSize]; self.nameLabel.font = [UIFont fontWithName:@"Chalkduster" size:userFontSize]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateTextSize) name:UIContentSizeCategoryDidChangeNotification object:nil]; }

AņpreferredFontDescriptorWithTextStyle:X·ŒF�ņƀǚäŏ�ȇ��

layoutƳò• øĥ�:Aņauto layoutex: labelŏsize�ƈKǭô�sizeìƸƁƳò

• øĥ�:ǢöƦŮ0�ŏsizeex:

UIFont *nameLabelFont = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];

CGSize nameLabelFontSize = [@"Peter Pan" sizeWithAttributes: @{NSFontAttributeName: nameLabelFont}];

Page 73: iOS 7 SDK特訓班

Motion Effects

Parallax effect

Ơ¡3DİK

Page 74: iOS 7 SDK特訓班

UIInterpolatingMotionEffect

- (void)viewDidLoad{ [super viewDidLoad];! UIInterpolatingMotionEffect *horizontalMotionEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis]; horizontalMotionEffect.minimumRelativeValue = @-50; horizontalMotionEffect.maximumRelativeValue = @50; [self.imageView addMotionEffect:horizontalMotionEffect];}

ŻÎUIMotionEffect

Ġ§šKdemo

Page 75: iOS 7 SDK特訓班

I�šKǂǯ horizontalMotionEffect.minimumRelativeValue = @-500; horizontalMotionEffect.maximumRelativeValue = @500;

Ġ§yœ�ÏÐ- (void)viewDidLoad{ [super viewDidLoad];

UIInterpolatingMotionEffect *horizontalMotionEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis]; horizontalMotionEffect.minimumRelativeValue = @-50; horizontalMotionEffect.maximumRelativeValue = @50; [self.imageView addMotionEffect:horizontalMotionEffect]; UIInterpolatingMotionEffect *verticalMotionEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.y" type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis]; verticalMotionEffect.minimumRelativeValue = @-50; verticalMotionEffect.maximumRelativeValue = @50; [self.imageView addMotionEffect:verticalMotionEffect];}

Page 76: iOS 7 SDK特訓班

Ġ§yœ�ÏÐUIMotionEffectGroup *group = [[UIMotionEffectGroup alloc] init];group.motionEffects = @[horizontalMotionEffect, verticalMotionEffect]; [self.imageView addMotionEffect:group];

modify CALayer

- (void)viewDidLoad{ [super viewDidLoad];

self.imageView.layer.borderColor = [UIColor yellowColor].CGColor; self.imageView.layer.borderWidth = 20; UIInterpolatingMotionEffect *horizontalMotionEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"layer.borderWidth" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis]; horizontalMotionEffect.minimumRelativeValue = @-20; horizontalMotionEffect.maximumRelativeValue = @20; [self.imageView addMotionEffect:horizontalMotionEffect];}

Page 77: iOS 7 SDK特訓班

ǝčźî

ƈƛmotion effect

• ö}ŻÎUIMotionEffectŏöȀ@

• �żkeyPathsAndRelativeValuesForViewerOffset:

http://www.teehanlax.com/blog/introduction-to-uimotioneffect/

Page 78: iOS 7 SDK特訓班

�cu�ȏ�cšKǎª

ƛǏ3Dïċ

UIKit Dynamics

Page 79: iOS 7 SDK特訓班

iOS 7FŏKʼn• Core Animation: Űmȏ�ýƛ�Kʼn

• but ... ąȌ*ȏ��/Ŗ��ňŏĽłƖĴ

• āŖ�ŏKʼnĔèŖ��ňŏĽłƖĴȏdzƜǢö¹ŽǛ½�¨ŏó�jĽł

�ƜơƊ• UIAnimator:

physical engineȎ

• UIDynamicBehavior: ĽłƖĴȎ UIAnimator�ŴaÇ'hƭ�ŏ`ŤĽłƖĴȏƛǏş�ŏKʼn

• UIDynamicItem protocol: Ǚ¸UIDynamicItem protocolŏĽ�RąƽČÆĴƙĽłƖĴ UIDynamicBehavior ³Ǹŏ�ƻ

• Reference View:UIAnimatorù�KʼnŏŦǩ

2DKʼn

Page 80: iOS 7 SDK特訓班

ĽłƖĴ• Gravity

• Collision

• Attachments

• Snap

• Forces

• Item properties

UIDynamicItem

@interface UIView : UIResponder<NSCoding, UIAppearance, UIAppearanceContainer, UIDynamicItem> {

Page 81: iOS 7 SDK特訓班

Architecture

Apple Sample CodeUIKit Dynamics Catalog

https://developer.apple.com/library/ios/samplecode/DynamicsCatalog

Page 82: iOS 7 SDK特訓班

ƈŇƏȇ

ǢGIǎª

APLGravityViewController

- (void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; UIDynamicAnimator *animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view]; UIGravityBehavior *gravityBeahvior = [[UIGravityBehavior alloc] initWithItems:@[self.square1]]; [animator addBehavior:gravityBeahvior]; self.animator = animator;}

@interface APLGravityViewController ()@property (nonatomic, weak) IBOutlet UIImageView *square1;@property (nonatomic, strong) UIDynamicAnimator *animator;@end

Page 83: iOS 7 SDK特訓班

­ũKʼn�ĜȆ

• ­ũUIDynamicAnimatorĽ�

• ­ũUIGravityBehaviorĽ�ȏƫ�UIGravityBehavior³ǸŏĽ�

• �UIGravityBehaviorĽ�IBUIDynamicAnimatorȏKʼnƘıǨ� !

UIGravityBehavior

Page 84: iOS 7 SDK特訓班

ȃƿŏğȔ gravityBeahvior.gravityDirection = CGVectorMake(1, -1);

ǢGIŜá- (void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated];

UIDynamicAnimator *animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view]; UIGravityBehavior *gravityBeahvior = [[UIGravityBehavior alloc] initWithItems:@[self.square1]]; [animator addBehavior:gravityBeahvior]; UICollisionBehavior *collisionBehavior = [[UICollisionBehavior alloc] initWithItems:@[self.square1]]; collisionBehavior.translatesReferenceBoundsIntoBoundary = YES; collisionBehavior.collisionDelegate = self; [animator addBehavior:collisionBehavior]; self.animator = animator; }

APLCollisionGravityViewController

Page 85: iOS 7 SDK特訓班

,ĭŜáȒĖ- (void)collisionBehavior:(UICollisionBehavior*)behavior beganContactForItem:(id<UIDynamicItem>)item withBoundaryIdentifier:(id<NSCopying>)identifier atPoint:(CGPoint)p{ [(UIView*)item setTintColor:[UIColor lightGrayColor]];

}

- (void)collisionBehavior:(UICollisionBehavior*)behavior endedContactForItem:(id<UIDynamicItem>)item withBoundaryIdentifier:(id<NSCopying>)identifier{ [(UIView*)item setTintColor:[UIColor darkGrayColor]];}

ǢGIŜá

Page 86: iOS 7 SDK特訓班

ŧĺƗ UIView *square2 = [[UIView alloc] initWithFrame: CGRectMake(160, 300, 100, 100)]; square2.backgroundColor = [UIColor blueColor]; [self.view addSubview:square2];

�YUIKit Dynamics³Ǹ

ŜŜĒUICollisionBehavior *collisionBehavior = [[UICollisionBehavior alloc] initWithItems:@[self.square1, square2]];

Page 87: iOS 7 SDK特訓班

œ×ØCItemŏProperty- (void)viewDidAppear:(BOOL)animated{ [super viewDidAppear:animated]; UIDynamicAnimator *animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view]; UIGravityBehavior *gravityBeahvior = [[UIGravityBehavior alloc] initWithItems:@[self.square1, self.square2]]; UICollisionBehavior *collisionBehavior = [[UICollisionBehavior alloc] initWithItems:@[self.square1, self.square2]]; collisionBehavior.translatesReferenceBoundsIntoBoundary = YES;

self.square2PropertiesBehavior = [[UIDynamicItemBehavior alloc] initWithItems:@[self.square2]]; self.square2PropertiesBehavior.elasticity = 0.5; self.square1PropertiesBehavior = [[UIDynamicItemBehavior alloc] initWithItems:@[self.square1]];

[animator addBehavior:self.square1PropertiesBehavior]; [animator addBehavior:self.square2PropertiesBehavior]; [animator addBehavior:gravityBeahvior]; [animator addBehavior:collisionBehavior]; self.animator = animator;}

APLItemPropertiesViewController

item property

• elasticity: ±Gȏ 0 ~ 1

• friction: àçGȏ0 ~ 1

• density: �ªȏǼƫþ1

• resistance: ĬǎGȎ0ƘŞ�ăĬǎ

• angularResistance: ơªŏĬǎG

• allowsRotation: þf^rotate

Page 88: iOS 7 SDK特訓班

±ǃĝƾ

Replay- (IBAction)replayAction:(id)sender{ // Moving an item does not reset its velocity. Here we do that manually // using the dynamic item behaviors, adding the inverse velocity for each // square. [self.square1PropertiesBehavior addLinearVelocity:CGPointMake(0, -1 * [self.square1PropertiesBehavior linearVelocityForItem:self.square1].y) forItem:self.square1]; self.square1.center = CGPointMake(90, 171); [self.animator updateItemUsingCurrentState:self.square1]; [self.square2PropertiesBehavior addLinearVelocity:CGPointMake(0, -1 * [self.square2PropertiesBehavior linearVelocityForItem:self.square2].y) forItem:self.square2]; self.square2.center = CGPointMake(230, 171); [self.animator updateItemUsingCurrentState:self.square2];}

Page 89: iOS 7 SDK特訓班

Combining behaviorsaddChildBehavior

- (instancetype)initWithWeight:(id<UIDynamicItem>)item suspendedFromPoint:(CGPoint)p{ self = [super init]; if (self) { UIGravityBehavior *gravityBehavior = [[UIGravityBehavior alloc] initWithItems:@[item]]; UIAttachmentBehavior *attachmentBehavior = [[UIAttachmentBehavior alloc] initWithItem:item attachedToAnchor:p]; UIAttachmentBehavior *draggingBehavior = [[UIAttachmentBehavior alloc] initWithItem:item attachedToAnchor:CGPointZero]; UIPushBehavior *pushBehavior = [[UIPushBehavior alloc] initWithItems:@[item] mode:UIPushBehaviorModeInstantaneous]; pushBehavior.active = NO; [self addChildBehavior:gravityBehavior]; [self addChildBehavior:attachmentBehavior]; [self addChildBehavior:pushBehavior]; self.draggingBehavior = draggingBehavior; self.pushBehavior = pushBehavior; } return self;}

APLPendulumBehavior

https://github.com/shu223/iOS7-Sampler