Upload
deeplove-pan
View
2.807
Download
1
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
iOS 7 SDKľƩŀ彼得潘
• IJ�ť
• ŭd´·IJ
• Ƒ�: AppŢ®ƫƦ2Ǧ -ȍȍ iPhone . iPad
• ĹÂƺȄ¤džȇ�Ţ£
2012¨ªŎ�DzƇȀ Top 6
AppŢ®ƫƦ2Ǧ
APPǨŌ
Macå�
�ę
ŔǪð�ƽĮ http://www.facebook.com/iphone.peterpan
http://deeploveapple.blogspot.tw
http://apppeterpan.blogspot.tw
FBűŵv
blog
ôwiki
ƨƵOhttp://peterpan.uservoice.com
http://deeploveiossdk.tumblr.comƎôwiki
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�
ľƊ• 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 )
§Ƕ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
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];}
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 (��ıŸ )
ƈƥ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
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ƣŌƽõāö(�ăȁŞÙãƧÀ)
wƄÿāöAppʼnǶ
Remote Notification��
Text Kit
Letterpress ( :ļQD)
ģąLetterpress ąLetterpress
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
şȊ$"Ĉō ŠȂƮ
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
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
ţ¶ÜĀ
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×ë
Machine Readable Code Detection
support barcode
• QR code
• Aztec
• EAN13
• EAN8
• UPC-E
• PDF417
• Code 93
• Code 39
• Code 39 mod 43
AVCaptureMetadataOutput
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
Multipeer Connectivity • ǟNJdeviceǩŏįǍj.Ljƽõ
• ǐ×ø®:infrastructure Wi-Fi networkspeer-to-peer Wi-FiBluetooth
Multipeer Connectivity
Inter-App Audio
• Appǩ.NjMIDIÒ�
• AppǩŏǷƧ.Lj
iBeaconbluetooth
,ĭǂǯ
ŌNjbeacon : iPhoneÈŬ�øśȇ
CLBeaconRegion
Map Kit
MKOverlayRenderer
4öŏoverlay
MKOverlayRenderer
Direction
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);
Sprite Kit
• �ņ�ŽOpenGL ES
• �ņ(JŬ�ølibraryȏ��Cocos 2D
• ā�ýxǨŌ2Dǒȑ
Game Controller
ǐ×: œ×ǐ×ÈþnjǔBluetooth
Game Controller
Game Controller
JavaScriptCore
• ø#¸objective-c{ƖjavascriptŢ®ŝ
• ø#¸javascript{Ɩobjective-cŢ®ŝ
Xcode 5öHƅŰ�
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[~�ƚ
öŏtemplateę�ƫ�
Asset Catalogs &Image Slicing
• ůłuĻŏ°��8• �ņ9Ǚ�ĸ�ŏėdƟ�
ex: @2x, ~ipad
• �ņ9¸Ţ®?÷ÖņŏuĻ• ƫ�App IconȒ���Ų
āø#ŏļćůłĘƠŒFbranchȏ=Ûbranchāø#
Debug Gauges
āø#ŏ¥ƕůłjAppMƚĉõůł
App Capability Management
Quick Look debug
Preview
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; }}
IBŏauto layout• IB�9ƈKI�constraint
• ā�ņŏö}constraintƫƦ
m0ĭƯXCTest
Continuous Integration
• ƈKbuildȏƈKĭƯȏƈKMƚApp
• ^ǁwsimulatorÈǐ×ŏ�Ė
• dzßǠOS X Mavericks Server
• ƣŌø®• ÊK• on commit
• periodically
Continuous Integration
āǑĜŏObjective-Cj
Foundation framework
Objective-CjFoundation framework
• module
• instancetype
• NSArray
module
• ƈKǐŴSDK3ŏframework
• ā¾ŏŷƷȒǩ• öŏimportƱĥ
ƈKǐŴ3ŏframework
ĵmoduleļć
Ƣĥ: ÊKI2MapKit.framework
moduleļć
ƈKǐŴ !
@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
instancetype
idkǾ
NSArray.h+ (id)array;
NSDictionary *dic = [NSArray array];
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
iOS 6 AppìļiOS 7
�ĕŢ®ȏ�cĕ®
iOS 7 iOS 6
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
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
App Icon
Ɖ�Ďƪ·1ö}asset catalogsȏĶ¶9ȌǚUse Asset Catalog
ö}asset catalogs
Fµasset catalogsƫ�ǹǶ
image.xcassetsŏAppIcon
ƫ��ciOSļćŏAppIconattributes inspectorps: ƪ·1ƳòDevelopment Target
• \support pngČ®
• 7�Č®ŏuĻǜþ·ÖņƉøĥ
• I2uĻ
Asset Catalogs
andy.png tony.png
self.imageView.image = [UIImage imageNamed:@"handsome"];
Asset Catalogs
andy.png tony.png chilam.png tai.pnglin.png
Image Slicing
tint color
tint color• ^�ȌǚŏUI0�
• activeŏUI0�ȏ��tab
• Ģ�UI0�ŏǿƊ (ex: UIButtonŏô�ǿƊ)
• Ƭ�button�ô�ƘŞ
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
ƫ�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
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ơƘČĕ®
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
���íŏnav bar & tab bar
nav barƝƒcontrollerʼnǶŏ�PǞcontrollerʼnǶȈª� �PǞtab barŏȈª( 519 = 568 - 49)
Extend Edges
barŏtranslucent
nva barĴtranslucentȏpěUnder Top barsŌÝ�ņtab barģątranslucentȏpěUnder Bottom bars�T�ņ
ƫ�Under Opaque Bars
ÕƆ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};
��
- (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
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Ǟƙƒ�
full screen�ǀȌ«ēƳò
• iOS 6 : (0, 0)
• iOS 7:
• only status bar : (0, 20)
• status bar + nav bar: (0, 64)
topLayoutGuide & bottomLayoutGuide
topLayoutGuide�Bnav barŏ©Ǟ
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]];
}
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
â·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:Ëƅńï
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ǮƓ
éƆ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Ļ
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ŏǿƊ
UINavigationControllerŏöÑƗe_scrolloF�ǹ
• Ó� ǝňe_scrollȏoBF�ǹ
• ǼƫǨl
• ex: -½ǣ
• Ǫǧ:
UINavigationController.h@property(nonatomic, readonly) UIGestureRecognizer *interactivePopGestureRecognizer;
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
öŏdeleteĕ®
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;
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ſƖ�ȓŏö}
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};
KÄô���
ƳòText Size
NJƠžƋŐĚ»ŏǍƧǣ
ƫ�Text Styles1
2
3
�UIFontDescriptor.h
UIFontTextStyleHeadlineUIFontTextStyleSubheadlineUIFontTextStyleBodyUIFontTextStyleFootnoteUIFontTextStyleCaption1UIFontTextStyleCaption2
�
�
self.nameLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
¸Ţ®ƫ�
¸ƫ�ìƸ�ȇ��
no change ?
Ǣö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ŏ�ȇ��
ƈƥ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}];
Motion Effects
Parallax effect
Ơ¡3DİK
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
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];}
Ġ§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];}
ǝčźî
ƈƛmotion effect
• ö}ŻÎUIMotionEffectŏöȀ@
• �żkeyPathsAndRelativeValuesForViewerOffset:
http://www.teehanlax.com/blog/introduction-to-uimotioneffect/
�cu�ȏ�cšKǎª
ƛǏ3Dïċ
UIKit Dynamics
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
ĽłƖĴ• Gravity
• Collision
• Attachments
• Snap
• Forces
• Item properties
UIDynamicItem
@interface UIView : UIResponder<NSCoding, UIAppearance, UIAppearanceContainer, UIDynamicItem> {
Architecture
Apple Sample CodeUIKit Dynamics Catalog
https://developer.apple.com/library/ios/samplecode/DynamicsCatalog
ƈŇƏȇ
Ǣ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
ũKʼn�ĜȆ
• ũUIDynamicAnimatorĽ�
• ũUIGravityBehaviorĽ�ȏƫ�UIGravityBehavior³ǸŏĽ�
• �UIGravityBehaviorĽ�IBUIDynamicAnimatorȏKʼnƘıǨ� !
UIGravityBehavior
ȃƿŏğȔ 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
,ĭŜáȒĖ- (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Ŝá
ŧĺƗ 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]];
œ×Ø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
±ǃĝƾ
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];}
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