SlideShare a Scribd company logo
iOS 7 SDK
彼得潘
•
•
• :App -
iPhone . iPad
•
2012
Top 6
App
APP
Mac
http://www.facebook.com/iphone.peterpan
http://deeploveapple.blogspot.tw
apppeterpan@gmail.com
http://apppeterpan.blogspot.tw
FB
blog
wiki
http://peterpan.uservoice.com
http://deeploveiossdk.tumblr.com
wiki
email
agenda
• iOS 7 SDK
• Xcode 5
• Objective-C Foundation framework
• iOS 6 App iOS 7 (UI )
•
• 1: Motion Effects (3D)
• 2: UIKit Dynamics (2D)
iOS 7 SDK
• UI
•
•
•
• device
•
•
•
•
• device
• App
• JavaScript
• iBeacon
• Machine Readable
Code Detection
• Apple Map
• Safari Reading list
•
UI
• UI
• Button
• nav bar search bar
• blurred background ( )
• image rendering mode (App iOS 7 )
• tint color (App iOS 7 )
• full screen status bar &
navigation bar (App iOS 7 )
UI
button
nav bar search bar
UISearchBar *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;
UINavigationController UINavigationBar
blurred background
( )
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];
• view controller
• CollectionView
• interactive transition
• Motion Effects ( )
• UIKit Dynamics ( )
view controller
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
CollectionView
WWDC 2013 Sample: iOS_CollectionViewTransition
ex: App YearsView Collections zoom in
https://developer.apple.com/downloads/index.action?name=WWDC%202013
interactive transition
• controller
• ex: scroll
UIViewControllerInteractiveTransitioning
Multitasking Enhancements
• (Background Fetch)
• ( Remote Notification )
silent push
( )
App
Remote Notification
Text Kit
Letterpress ( )
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.h
UIKIT_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 = @"
";
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:@"
"]];
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
AirDrop
available on iPhone 5, iPad (4th generation), iPad mini, and iPod touch (5th generation)
requires an iCloud account
:Wifi Bluetooth
AirDrop
• 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
SSReadingList
Safari Reading list
NSURL *url = [NSURL URLWithString:@"https:/
/www.facebook.com/iphone.peterpan"];
[[SSReadingList defaultReadingList]
addReadingListItemWithURL:url title:@" "
previewText:@" " error:nil];
• CIDetectorSmile
• CIDetectorEyeBlink
Multipeer Connectivity
• device
• :
infrastructure Wi-Fi networks
peer-to-peer Wi-Fi
Bluetooth
Multipeer Connectivity
Inter-App Audio
• App MIDI
• App
iBeacon
bluetooth
beacon : iPhone
CLBeaconRegion
Map Kit
MKOverlayRenderer
overlay
MKOverlayRenderer
Direction
AVSpeechSynthesis
AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc]
init];
AVSpeechUtterance *utterance = [AVSpeechUtterance
speechUtteranceWithString:@" "];
[synthesizer speakUtterance:utterance];
AVSpeechSynthesizer
AVSpeechSynthesizer:
• M7
• 5s support
• CMStepCounter
• typedef void (^CMStepUpdateHandler)(NSInteger
numberOfSteps, NSDate *timestamp, NSError
*error);
Sprite Kit
• OpenGL ES
• library Cocos 2D
• 2D
Game Controller
: Bluetooth
Game Controller
Game Controller
JavaScriptCore
• objective-c javascript
• javascript objective-c
Xcode 5
Xcode 5
• UI
•
• Asset Catalogs
• Image Slicing
•
• App
• Interface Builder Preview
• support 64 bit iOS (iPhone 5s)
•
• App Capability
• Debug Gauges
• XCTest
• Continuous Integration
• Autolayout
• Quick Look
•
Xcode
• OS X Mavericks
template
Asset Catalogs &
Image Slicing
•
•
ex: @2x, ~ipad
•
• App Icon
branch
branch
Debug Gauges
App
App Capability
Management
Quick Look debug
Preview
Preview
/**
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 constraint
• constraint
XCTest
Continuous Integration
• build App
• simulator
• OS X Mavericks Server
•
•
• on commit
• periodically
Continuous Integration
Objective-C
Foundation framework
Objective-C
Foundation framework
• module
• instancetype
• NSArray
module
• SDK framework
•
• import
framework
module
: MapKit.framework
module
!
@import
• @import QuartzCore;
• @import QuartzCore.CoreAnimation;
• #import @import
ex:
(1) #import <UIKit/UIKit.h>
@import UIKit;
(2) #import <iAd/ADBannerView.h>
@import iAd.ADBannerView;
• module
#import
enable modules
instancetype
id
NSArray.h
+ (id)array;
NSDictionary *dic = [NSArray array];
instancetype
NSArray.h
+ (instancetype)array;
return type
array
NSArray.h
- (id)firstObject NS_AVAILABLE(10_6, 4_0);
- (id)lastObject;
firstObject iOS 7
NSArray *array = [[NSArray alloc] init];
NSLog(@"array %@", array[0]);
NSArray *array = [[NSArray alloc] init];
NSLog(@"array %@", [array firstObject]);
nil
iOS 6 App iOS 7
iOS 7 iOS 6
iOS 6 App iOS 7
• App Icon
• Asset Catalogs Image Slicing
• tint color
• iOS
• full screen status bar &
navigation bar
• image render mode
• interactivePopGestureRecognizer
• keyboard , picker & alert view
App Icon size
App Icon (pixel)
iPhone 57 * 57
iPhone Retina 114 * 114
iPad (iPad mini) 72 * 72
iPad Retina 144 * 144
iPhone Retina iOS 7 120 * 120
iPad (iPad mini) iOS 7 76 * 76
iPad Retina iOS 7 152 * 152
iOS 7
Retina
App iPhone App iOS 7
-> retina
size
Launch Image (pixel)
iPhone 3.5 320 * 480
iPhone Retina 3.5 640 * 960
iPhone Retina 4 640 * 1136
iPad (iPad mini) 768 * 1024
1024 * 768
iPad Retina 1536 * 2048
2048 * 1536
full screen status bar
App Icon
asset catalogs Use Asset Catalog
asset catalogs
asset catalogs
image.xcassets AppIcon
iOS AppIcon
attributes inspectorps: Development Target
• support png
•
•
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
• UI
• active UI tab
• UI (ex: UIButton )
• button
UIView tintColor property
• default: blue
• tintColor :
1.
2. superview
tintColor superview
3. superview tintColor
• App
1. UI tint color
2. App 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 property iOS 7
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
iOS SDK: crash
iOS 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;
iOS 7 barTintColor
full screen
status bar
navigation bar
cell:
UITableViewStyleGrouped
view controller’s view size
• iOS 7 view size full
screen
• iOS 6 view size full screen
• status bar black translucent
• controller wantsFullScreenLayout
YES
• navigation bar translucent YES
controller
320 * 568
nav bar & tab bar
nav bar controller
controller tab bar
( 519 = 568 - 49)
Extend Edges
bar translucent
nva bar translucent Under Top bars
tab bar translucent Under Bottom bars
Under Opaque Bars
bar
455 = 568 - 20 - 44 -49
UIViewController.h
@property(nonatomic,assign) UIRectEdge edgesForExtendedLayout;
@property(nonatomic,assign) BOOL extendedLayoutIncludesOpaqueBars;
UIGeometry.h
typedef 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
automaticallyAdjustsScrollViewInsets
UIViewController.h
@property(nonatomic,assign) BOOL automaticallyAdjustsScrollViewInsets;
UIScrollView.h
@property(nonatomic) UIEdgeInsets contentInset;
UIGeometry.h
typedef struct UIEdgeInsets {
CGFloat top, left, bottom, right;
} UIEdgeInsets;
inset {64, 0, 0, 0}
content start from 64
automaticallyAdjustsScrollViewInsets NO
full screen
• iOS 6 : (0, 0)
• iOS 7:
• only status bar : (0, 20)
• status bar + nav bar: (0, 64)
topLayoutGuide &
bottomLayoutGuide
topLayoutGuide
nav bar
topLayoutGuide &
bottomLayoutGuide
topLayoutGuide status 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
UIBarPositionAny
UIBarPositionBottom
UIBarPositionTop
UIBarPositionTopAttached
- (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;
}
status bar
: status bar
:
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleLightContent;
}
- (UIStatusBarStyle)preferredStatusBarStyle
{
return UIStatusBarStyleDefault;
}
( )
method controller status bar
controller default
status bar
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
return YES;
}
status bar controller
View controller-based status bar appearance
(UIViewControllerBasedStatusBarAppearance)
NO setStatusBarStyle:
hide status bar
view controller
[[UIApplication sharedApplication]
setStatusBarHidden:isHide
withAnimation:UIStatusBarAnimationFade];
!
hide status bar
- (BOOL)prefersStatusBarHidden
{
return YES;
}
controller status bar
controller
[[UIApplication sharedApplication] setStatusBarHidden:YES
withAnimation:UIStatusBarAnimationFade];
work !
status bar
nav bar
• scroll
• 44 64
• nav bar 64
point
bar button item
UIImage *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 6 initWithCustomView
image render mode
UIImage.h
typedef NS_ENUM(NSInteger, UIImageRenderingMode) {
UIImageRenderingModeAutomatic,
UIImageRenderingModeAlwaysOriginal,
UIImageRenderingModeAlwaysTemplate,
}
UIImageRenderingModeAlwaysTemplate:
tint color
UINavigationController
scroll
• scroll
•
• ex:
• :
UINavigationController.h
@property(nonatomic, readonly) UIGestureRecognizer
*interactivePopGestureRecognizer;
self.navigationController.interactivePopGestureRecognizer.enabled
= NO;
delete
tab bar image
UITabBarItem.h
@property(nonatomic,retain) UIImage *selectedImage;
tint color
tab
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
self.picker.backgroundColor =
[UIColor whiteColor];
:
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 view
UIAlertView *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.h
typedef NS_ENUM(NSInteger, UIAlertViewStyle) {
UIAlertViewStyleDefault = 0,
UIAlertViewStyleSecureTextInput,
UIAlertViewStylePlainTextInput,
UIAlertViewStyleLoginAndPasswordInput
};
Text Size
Text Styles
1
2
3
UIFontDescriptor.h
UIFontTextStyleHeadline
UIFontTextStyleSubheadline
UIFontTextStyleBody
UIFontTextStyleFootnote
UIFontTextStyleCaption1
UIFontTextStyleCaption2
self.nameLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
no change ?
App
-(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];
}
:
-(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];
}
preferredFontDescriptorWithTextStyle:
layout
• :
auto layout
ex: label size size
• :
size
ex:
UIFont *nameLabelFont = [UIFont
preferredFontForTextStyle:UIFontTextStyleHeadline];
CGSize nameLabelFontSize = [@"Peter Pan" sizeWithAttributes:
@{NSFontAttributeName: nameLabelFont}];
Motion Effects
Parallax effect
3D
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
demo
horizontalMotionEffect.minimumRelativeValue = @-500;
horizontalMotionEffect.maximumRelativeValue = @500;
- (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];
}
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/
3D
UIKit Dynamics
iOS 7
• Core Animation:
• but
...
•
• UIAnimator:
physical engine
• UIDynamicBehavior:
UIAnimator
• UIDynamicItem protocol:
UIDynamicItem protocol
UIDynamicBehavior
• ReferenceView:
UIAnimator
2D
• Gravity
• Collision
• Attachments
• Snap
• Forces
• Item properties
UIDynamicItem
@interface UIView : UIResponder<NSCoding,
UIAppearance, UIAppearanceContainer,
UIDynamicItem> {
Architecture
Apple Sample Code
UIKit Dynamics Catalog
https://developer.apple.com/library/ios/samplecode/DynamicsCatalog
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
• UIDynamicAnimator
• UIGravityBehavior
UIGravityBehavior
• UIGravityBehavior
UIDynamicAnimator !
UIGravityBehavior
gravityBeahvior.gravityDirection = CGVectorMake(1, -1);
- (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]];
}
UIView *square2 = [[UIView alloc] initWithFrame:
CGRectMake(160, 300, 100, 100)];
square2.backgroundColor = [UIColor blueColor];
[self.view addSubview:square2];
UIKit Dynamics
UICollisionBehavior *collisionBehavior = [[UICollisionBehavior
alloc] initWithItems:@[self.square1, square2]];
Item 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: 0 ~ 1
• friction: 0 ~ 1
• density: 1
• resistance: 0
• angularResistance:
• allowsRotation: 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 behaviors
addChildBehavior
- (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

More Related Content

PDF
Advance text rendering in i os
PDF
Hi performance table views with QuartzCore and CoreText
PDF
FI MUNI 2012 - iOS Basics
PDF
From YUI3 to K2
PDF
REST/JSON/CoreData Example Code - A Tour
PDF
Intro to node.js - Ran Mizrahi (28/8/14)
PDF
Declarative UI on iOS without SwiftUI (中文)
PDF
Medium TechTalk — iOS
Advance text rendering in i os
Hi performance table views with QuartzCore and CoreText
FI MUNI 2012 - iOS Basics
From YUI3 to K2
REST/JSON/CoreData Example Code - A Tour
Intro to node.js - Ran Mizrahi (28/8/14)
Declarative UI on iOS without SwiftUI (中文)
Medium TechTalk — iOS

What's hot (19)

PPTX
Academy PRO: React native - navigation
PDF
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
PDF
Bootstrap과 UI-Bootstrap
PDF
Intro To JavaScript Unit Testing - Ran Mizrahi
PDF
Django Heresies
PDF
iPhone dev intro
KEY
Desenvolvimento iOS - Aula 4
KEY
An in-depth look at jQuery UI
PPTX
How dojo works
PPT
Ember.js Tokyo event 2014/09/22 (English)
PDF
ScalikeJDBC Tutorial for Beginners
PDF
Connect.Tech- Level Up Your Game With TravisCI
PPTX
Extending Studio
PDF
Django at Scale
PDF
Client-side MVC with Backbone.js (reloaded)
PDF
Introduction to node.js by Ran Mizrahi @ Reversim Summit
PPTX
IndexedDB - Querying and Performance
PDF
Dependency Injection @ AngularJS
PDF
Building scalable applications with angular js
Academy PRO: React native - navigation
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Bootstrap과 UI-Bootstrap
Intro To JavaScript Unit Testing - Ran Mizrahi
Django Heresies
iPhone dev intro
Desenvolvimento iOS - Aula 4
An in-depth look at jQuery UI
How dojo works
Ember.js Tokyo event 2014/09/22 (English)
ScalikeJDBC Tutorial for Beginners
Connect.Tech- Level Up Your Game With TravisCI
Extending Studio
Django at Scale
Client-side MVC with Backbone.js (reloaded)
Introduction to node.js by Ran Mizrahi @ Reversim Summit
IndexedDB - Querying and Performance
Dependency Injection @ AngularJS
Building scalable applications with angular js
Ad

Viewers also liked (10)

PDF
利用 iOS App 技術創業的 13 個方法
PDF
第一次程式親密接觸
PDF
Standford 2015 week8
PDF
Standford 2015 week9
PDF
打造你的第一個iPhone APP
PDF
如何變成iOS App開發魔法師
PDF
不能承受的感動 - iOS App實機測試
PDF
Standford 2015 week7: 1. Unwind Segues, Alerts, Timers, View Animation 2. Dyn...
PDF
為愛打造App
PDF
iOS 入門教學
利用 iOS App 技術創業的 13 個方法
第一次程式親密接觸
Standford 2015 week8
Standford 2015 week9
打造你的第一個iPhone APP
如何變成iOS App開發魔法師
不能承受的感動 - iOS App實機測試
Standford 2015 week7: 1. Unwind Segues, Alerts, Timers, View Animation 2. Dyn...
為愛打造App
iOS 入門教學
Ad

Similar to iOS 7 SDK特訓班 (20)

PPT
Programming iOS in C#
KEY
UIWebView Tips
KEY
I phone勉強会 (2011.11.23)
PDF
MOPCON 2014 - Best software architecture in app development
PDF
Conceitos e prática no desenvolvimento iOS - Mobile Conf 2014
PDF
Leaving Interface Builder Behind
KEY
iPhone/iPad开发讲座 第五讲 定制视图和多点触摸
PDF
Style vs. Content and Clean Theming in iOS
PDF
Developing iOS REST Applications
PPTX
Mobile App Development: Primi passi con NativeScript e Angular 2
PDF
iOS 2 - The practical Stuff
PDF
MFF UK - Advanced iOS Topics
KEY
漫游iOS开发指南
PDF
Webエンジニアから見たiOS5
KEY
iOS Einführung am Beispiel von play NEXT TEE
PDF
Heroku pop-behind-the-sense
PDF
Cocoa Heads Tricity - Design Patterns
PDF
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)
KEY
iPhone Development Intro
Programming iOS in C#
UIWebView Tips
I phone勉強会 (2011.11.23)
MOPCON 2014 - Best software architecture in app development
Conceitos e prática no desenvolvimento iOS - Mobile Conf 2014
Leaving Interface Builder Behind
iPhone/iPad开发讲座 第五讲 定制视图和多点触摸
Style vs. Content and Clean Theming in iOS
Developing iOS REST Applications
Mobile App Development: Primi passi con NativeScript e Angular 2
iOS 2 - The practical Stuff
MFF UK - Advanced iOS Topics
漫游iOS开发指南
Webエンジニアから見たiOS5
iOS Einführung am Beispiel von play NEXT TEE
Heroku pop-behind-the-sense
Cocoa Heads Tricity - Design Patterns
Hızlı Cocoa Geliştirme (Develop your next cocoa app faster!)
iPhone Development Intro

More from 彼得潘 Pan (13)

PDF
創作 MusicKit 告白情歌
PDF
如何變成 iOS App 開發魔法師 (1 小時)
PDF
如何變成 iOS App 開發魔法師
PDF
Xcode 的 git 版本管理
PDF
消滅永生不死吸血鬼物件的 ARC
PDF
你的程式開發初體驗 (以Swift為例)
PDF
Standford 2015 week6
PDF
Standford 2015 week5: 1.View Controller Lifecycle, Autolayout 2. Scroll View ...
PDF
Standford 2015 week4: 1.Protocols and Delegation, Gestures 2. Multiple MVCs
PDF
Standford 2015 week3: Objective-C Compatibility, Property List, Views
PDF
Standford 2015 iOS讀書會 week2: 1. Applying MVC 2. More Swift and Foundation Fra...
PDF
Standford 2015 iOS讀書會 week1: 1.Logistics , iOS 8 Overview 2. More Xcode and S...
PDF
打造你的第一個 iOS App
創作 MusicKit 告白情歌
如何變成 iOS App 開發魔法師 (1 小時)
如何變成 iOS App 開發魔法師
Xcode 的 git 版本管理
消滅永生不死吸血鬼物件的 ARC
你的程式開發初體驗 (以Swift為例)
Standford 2015 week6
Standford 2015 week5: 1.View Controller Lifecycle, Autolayout 2. Scroll View ...
Standford 2015 week4: 1.Protocols and Delegation, Gestures 2. Multiple MVCs
Standford 2015 week3: Objective-C Compatibility, Property List, Views
Standford 2015 iOS讀書會 week2: 1. Applying MVC 2. More Swift and Foundation Fra...
Standford 2015 iOS讀書會 week1: 1.Logistics , iOS 8 Overview 2. More Xcode and S...
打造你的第一個 iOS App

Recently uploaded (20)

PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
MYSQL Presentation for SQL database connectivity
PPT
Teaching material agriculture food technology
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Modernizing your data center with Dell and AMD
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
cuic standard and advanced reporting.pdf
PPTX
Cloud computing and distributed systems.
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Machine learning based COVID-19 study performance prediction
PDF
Empathic Computing: Creating Shared Understanding
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
A Presentation on Artificial Intelligence
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Network Security Unit 5.pdf for BCA BBA.
MYSQL Presentation for SQL database connectivity
Teaching material agriculture food technology
The AUB Centre for AI in Media Proposal.docx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Modernizing your data center with Dell and AMD
NewMind AI Monthly Chronicles - July 2025
cuic standard and advanced reporting.pdf
Cloud computing and distributed systems.
Spectral efficient network and resource selection model in 5G networks
Machine learning based COVID-19 study performance prediction
Empathic Computing: Creating Shared Understanding
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Building Integrated photovoltaic BIPV_UPV.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
A Presentation on Artificial Intelligence
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Unlocking AI with Model Context Protocol (MCP)
How UI/UX Design Impacts User Retention in Mobile Apps.pdf

iOS 7 SDK特訓班

  • 1. iOS 7 SDK 彼得潘 • • • :App - iPhone . iPad • 2012 Top 6 App
  • 3. agenda • iOS 7 SDK • Xcode 5 • Objective-C Foundation framework • iOS 6 App iOS 7 (UI ) • • 1: Motion Effects (3D) • 2: UIKit Dynamics (2D) iOS 7 SDK
  • 4. • UI • • • • device • • • • • device • App • JavaScript • iBeacon • Machine Readable Code Detection • Apple Map • Safari Reading list • UI • UI • Button • nav bar search bar • blurred background ( ) • image rendering mode (App iOS 7 ) • tint color (App iOS 7 ) • full screen status bar & navigation bar (App iOS 7 )
  • 5. UI button nav bar search bar UISearchBar *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; UINavigationController UINavigationBar
  • 6. blurred background ( ) 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]; }
  • 7. UIToolbar UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 20, 320, 44)]; [self.view addSubview:toolBar]; toolBar.barTintColor = [UIColor blueColor]; • view controller • CollectionView • interactive transition • Motion Effects ( ) • UIKit Dynamics ( )
  • 9. interactive transition • controller • ex: scroll UIViewControllerInteractiveTransitioning Multitasking Enhancements • (Background Fetch) • ( Remote Notification ) silent push ( )
  • 11. Text Kit Letterpress ( ) Letterpress Letterpress
  • 12. 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.h UIKIT_EXTERN NSString *const NSTextEffectLetterpressStyle NS_AVAILABLE_IOS(7_0); Exclusion paths
  • 13. Exclusion paths UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 40, 320, 400)]; textView.backgroundColor = [UIColor clearColor]; textView.textColor = [UIColor whiteColor]; textView.text = @" "; 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
  • 14. 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:@" "]]; 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
  • 15. AirDrop available on iPhone 5, iPad (4th generation), iPad mini, and iPod touch (5th generation) requires an iCloud account :Wifi Bluetooth AirDrop • UIActivityViewController • Share • NSString & NSAttributedString ( Notes.app ) • UIImage & AVAsset (Photos.app ) • NSURL • Safari.app • App
  • 16. Machine Readable Code Detection support barcode • QR code • Aztec • EAN13 • EAN8 • UPC-E • PDF417 • Code 93 • Code 39 • Code 39 mod 43 AVCaptureMetadataOutput
  • 17. SSReadingList Safari Reading list NSURL *url = [NSURL URLWithString:@"https:/ /www.facebook.com/iphone.peterpan"]; [[SSReadingList defaultReadingList] addReadingListItemWithURL:url title:@" " previewText:@" " error:nil]; • CIDetectorSmile • CIDetectorEyeBlink
  • 18. Multipeer Connectivity • device • : infrastructure Wi-Fi networks peer-to-peer Wi-Fi Bluetooth Multipeer Connectivity
  • 19. Inter-App Audio • App MIDI • App iBeacon bluetooth beacon : iPhone CLBeaconRegion
  • 22. AVSpeechSynthesis AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc] init]; AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@" "]; [synthesizer speakUtterance:utterance]; AVSpeechSynthesizer AVSpeechSynthesizer: • M7 • 5s support • CMStepCounter • typedef void (^CMStepUpdateHandler)(NSInteger numberOfSteps, NSDate *timestamp, NSError *error);
  • 23. Sprite Kit • OpenGL ES • library Cocos 2D • 2D Game Controller : Bluetooth
  • 25. JavaScriptCore • objective-c javascript • javascript objective-c Xcode 5
  • 26. Xcode 5 • UI • • Asset Catalogs • Image Slicing • • App • Interface Builder Preview • support 64 bit iOS (iPhone 5s) • • App Capability • Debug Gauges • XCTest • Continuous Integration • Autolayout • Quick Look • Xcode • OS X Mavericks
  • 27. template Asset Catalogs & Image Slicing • • ex: @2x, ~ipad • • App Icon
  • 31. Preview /** 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; } }
  • 32. IB auto layout • IB constraint • constraint XCTest
  • 33. Continuous Integration • build App • simulator • OS X Mavericks Server • • • on commit • periodically Continuous Integration
  • 37. @import • @import QuartzCore; • @import QuartzCore.CoreAnimation; • #import @import ex: (1) #import <UIKit/UIKit.h> @import UIKit; (2) #import <iAd/ADBannerView.h> @import iAd.ADBannerView; • module #import enable modules
  • 39. instancetype NSArray.h + (instancetype)array; return type array NSArray.h - (id)firstObject NS_AVAILABLE(10_6, 4_0); - (id)lastObject; firstObject iOS 7 NSArray *array = [[NSArray alloc] init]; NSLog(@"array %@", array[0]); NSArray *array = [[NSArray alloc] init]; NSLog(@"array %@", [array firstObject]); nil
  • 40. iOS 6 App iOS 7 iOS 7 iOS 6
  • 41. iOS 6 App iOS 7 • App Icon • Asset Catalogs Image Slicing • tint color • iOS • full screen status bar & navigation bar • image render mode • interactivePopGestureRecognizer • keyboard , picker & alert view App Icon size App Icon (pixel) iPhone 57 * 57 iPhone Retina 114 * 114 iPad (iPad mini) 72 * 72 iPad Retina 144 * 144 iPhone Retina iOS 7 120 * 120 iPad (iPad mini) iOS 7 76 * 76 iPad Retina iOS 7 152 * 152
  • 42. iOS 7 Retina App iPhone App iOS 7 -> retina size Launch Image (pixel) iPhone 3.5 320 * 480 iPhone Retina 3.5 640 * 960 iPhone Retina 4 640 * 1136 iPad (iPad mini) 768 * 1024 1024 * 768 iPad Retina 1536 * 2048 2048 * 1536 full screen status bar
  • 43. App Icon asset catalogs Use Asset Catalog asset catalogs
  • 45. iOS AppIcon attributes inspectorps: Development Target • support png • • Asset Catalogs andy.png tony.png self.imageView.image = [UIImage imageNamed:@"handsome"];
  • 46. Asset Catalogs andy.png tony.png chilam.png tai.pnglin.png Image Slicing
  • 47. tint color tint color • UI • active UI tab • UI (ex: UIButton ) • button
  • 48. UIView tintColor property • default: blue • tintColor : 1. 2. superview tintColor superview 3. superview tintColor • App 1. UI tint color 2. App 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
  • 49. tint color self.view.tintColor = [UIColor orangeColor]; iOS 6 Crash tintColor property iOS 7 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 iOS SDK: crash iOS deprecated SDK: do nothing
  • 50. iOS 6 tintColor UINavigationBar.h @property(nonatomic,retain) UIColor *tintColor; @property(nonatomic,retain) UIColor *barTintColor NS_AVAILABLE_IOS(7_0) UI_APPEARANCE_SELECTOR; iOS 7 barTintColor full screen status bar navigation bar cell: UITableViewStyleGrouped
  • 51. view controller’s view size • iOS 7 view size full screen • iOS 6 view size full screen • status bar black translucent • controller wantsFullScreenLayout YES • navigation bar translucent YES controller 320 * 568
  • 52. nav bar & tab bar nav bar controller controller tab bar ( 519 = 568 - 49) Extend Edges
  • 53. bar translucent nva bar translucent Under Top bars tab bar translucent Under Bottom bars Under Opaque Bars
  • 54. bar 455 = 568 - 20 - 44 -49 UIViewController.h @property(nonatomic,assign) UIRectEdge edgesForExtendedLayout; @property(nonatomic,assign) BOOL extendedLayoutIncludesOpaqueBars; UIGeometry.h typedef NS_OPTIONS(NSUInteger, UIRectEdge) { UIRectEdgeNone = 0, UIRectEdgeTop = 1 << 0, UIRectEdgeLeft = 1 << 1, UIRectEdgeBottom = 1 << 2, UIRectEdgeRight = 1 << 3, UIRectEdgeAll = UIRectEdgeTop | UIRectEdgeLeft | UIRectEdgeBottom | UIRectEdgeRight };
  • 55. - (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
  • 56. automaticallyAdjustsScrollViewInsets UIViewController.h @property(nonatomic,assign) BOOL automaticallyAdjustsScrollViewInsets; UIScrollView.h @property(nonatomic) UIEdgeInsets contentInset; UIGeometry.h typedef struct UIEdgeInsets { CGFloat top, left, bottom, right; } UIEdgeInsets; inset {64, 0, 0, 0} content start from 64 automaticallyAdjustsScrollViewInsets NO
  • 57. full screen • iOS 6 : (0, 0) • iOS 7: • only status bar : (0, 20) • status bar + nav bar: (0, 64) topLayoutGuide & bottomLayoutGuide topLayoutGuide nav bar
  • 58. topLayoutGuide & bottomLayoutGuide topLayoutGuide status 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]]; }
  • 59. bar UIBarPositionAny UIBarPositionBottom UIBarPositionTop UIBarPositionTopAttached - (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; } status bar : status bar
  • 60. : - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleLightContent; } - (UIStatusBarStyle)preferredStatusBarStyle { return UIStatusBarStyleDefault; } ( ) method controller status bar controller default status bar - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions { [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; return YES; } status bar controller View controller-based status bar appearance (UIViewControllerBasedStatusBarAppearance) NO setStatusBarStyle:
  • 61. hide status bar view controller [[UIApplication sharedApplication] setStatusBarHidden:isHide withAnimation:UIStatusBarAnimationFade]; ! hide status bar - (BOOL)prefersStatusBarHidden { return YES; } controller status bar
  • 63. bar button item UIImage *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 6 initWithCustomView image render mode UIImage.h typedef NS_ENUM(NSInteger, UIImageRenderingMode) { UIImageRenderingModeAutomatic, UIImageRenderingModeAlwaysOriginal, UIImageRenderingModeAlwaysTemplate, } UIImageRenderingModeAlwaysTemplate: tint color
  • 64. UINavigationController scroll • scroll • • ex: • : UINavigationController.h @property(nonatomic, readonly) UIGestureRecognizer *interactivePopGestureRecognizer; self.navigationController.interactivePopGestureRecognizer.enabled = NO; delete
  • 65. tab bar image UITabBarItem.h @property(nonatomic,retain) UIImage *selectedImage; tint color tab keyboard default UITextInputTraits.h UIKeyboardAppearanceDefault UIKeyboardAppearanceDark UIKeyboardAppearanceLight textField.keyboardAppearance = UIKeyboardAppearanceDark;
  • 66. keyboard UIScrollView.h typedef NS_ENUM(NSInteger, UIScrollViewKeyboardDismissMode) { UIScrollViewKeyboardDismissModeNone, UIScrollViewKeyboardDismissModeOnDrag, UIScrollViewKeyboardDismissModeInteractive, } scrollView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive; UIScrollViewKeyboardDismissModeOnDrag: scroll (ex: ) UIScrollViewKeyboardDismissModeInteractive: scroll (ex: ) Picker self.picker.backgroundColor = [UIColor whiteColor]; :
  • 67. 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 view UIAlertView *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.h typedef NS_ENUM(NSInteger, UIAlertViewStyle) { UIAlertViewStyleDefault = 0, UIAlertViewStyleSecureTextInput, UIAlertViewStylePlainTextInput, UIAlertViewStyleLoginAndPasswordInput };
  • 71. App -(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]; } :
  • 72. -(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]; } preferredFontDescriptorWithTextStyle: layout • : auto layout ex: label size size • : size ex: UIFont *nameLabelFont = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]; CGSize nameLabelFontSize = [@"Peter Pan" sizeWithAttributes: @{NSFontAttributeName: nameLabelFont}];
  • 74. 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 demo
  • 75. horizontalMotionEffect.minimumRelativeValue = @-500; horizontalMotionEffect.maximumRelativeValue = @500; - (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]; }
  • 76. 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]; }
  • 77. motion effect • UIMotionEffect • keyPathsAndRelativeValuesForViewerOffset: http://www.teehanlax.com/blog/introduction-to-uimotioneffect/
  • 79. iOS 7 • Core Animation: • but ... • • UIAnimator: physical engine • UIDynamicBehavior: UIAnimator • UIDynamicItem protocol: UIDynamicItem protocol UIDynamicBehavior • ReferenceView: UIAnimator 2D
  • 80. • Gravity • Collision • Attachments • Snap • Forces • Item properties UIDynamicItem @interface UIView : UIResponder<NSCoding, UIAppearance, UIAppearanceContainer, UIDynamicItem> {
  • 81. Architecture Apple Sample Code UIKit Dynamics Catalog https://developer.apple.com/library/ios/samplecode/DynamicsCatalog
  • 82. 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
  • 83. • UIDynamicAnimator • UIGravityBehavior UIGravityBehavior • UIGravityBehavior UIDynamicAnimator ! UIGravityBehavior
  • 84. gravityBeahvior.gravityDirection = CGVectorMake(1, -1); - (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
  • 85. - (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]]; }
  • 86. UIView *square2 = [[UIView alloc] initWithFrame: CGRectMake(160, 300, 100, 100)]; square2.backgroundColor = [UIColor blueColor]; [self.view addSubview:square2]; UIKit Dynamics UICollisionBehavior *collisionBehavior = [[UICollisionBehavior alloc] initWithItems:@[self.square1, square2]];
  • 87. Item 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: 0 ~ 1 • friction: 0 ~ 1 • density: 1 • resistance: 0 • angularResistance: • allowsRotation: rotate
  • 88. 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]; }
  • 89. Combining behaviors addChildBehavior - (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