動畫
UIKit
動畫用于交互設計:
更好的展示:relationship,structure,cause & effect
UIView提供的動畫支持
(UIViewAnimation): depricated
UIView(UIViewAnimationWithBlocks)
+(void)animateWithDuration:(NSTimeInterval) delay:(NSTimeInterval) options:(UIViewAnimationOptions) animations:(void (^)(void)) completion:(void(^ _nullable)(BOOL finished));
+(void)animateWithDuration:(NSTimeInterval) animations:(void (^)(void)) completion:(void(^ _nullable)(BOOL finished))
+(void)animateWithDuration:(NSTimeInterval) animations:(void (^)(void))
Autolayout 環境下的動畫
修改 constraint
-[view setNeedsUpdateConstraints]
-[view layoutIfNeeded] in animation block
[UIViewsetAnimationCurve:UIViewAnimationCurveEaseInOut]設置動畫曲線,動畫曲線指定的是動畫進入和退出的方式,它也有幾個常量:
UIViewAnimationCurveEaseInOut
UIViewAnimationCurveEaseIn
UIViewAnimationCurveEaseOut
UIViewAnimationCurveLinear
setAnimationTransition:forView:cache:方法第一個參數定義動畫類型,第二個參數是當前視圖對象,第三個參數上使用緩沖區。
View Transition
切換動畫:用動畫過程提示已經切換到新界面了。
UIView具有一個UIViewAnimationTransition屬性可以設定動畫,這些動畫是iOS提供幾個常用動畫有:
UIViewAnimationTransitionNone
UIViewAnimationTransitionFlipFromLeft
UIViewAnimationTransitionFlipFromRight
UIViewAnimationTransitionCurlUp
UIViewAnimationTransitionCurlDown
修改子視圖顯示時:
視圖替換:
1.從 fromView 切換到toView
2.一般是場景切換,變化較大
CoreAnimation
Core Animation負責所有的滾動、旋轉、縮小和放大以及所有的iOS動畫效果。其中UIKit類通常都有animated:參數部分,它可以允許是否使用動畫。
Core Animation還與Quartz緊密結合在一起,每個UIView都關聯到一個CALayer對象,CALayer是Core Animation中的圖層。
Core Animation創建動畫時候會修改CALayer屬性,然后讓這些屬性流暢地變化。Core Animation相關知識點:
圖層,圖層是動畫發生的地方,CALayer總是與UIView關聯,通過layer屬性訪問。
隱式動畫,這是一種最簡單的動畫,不用設置定時器,不用考慮線程或者重畫。
Core Animation 認為動畫總是需要的,所以默認開著;修改layer的可動畫屬性時,會自動觸發動畫。
顯式動畫,是一種使用CABasicAnimation創建的動畫,通過CABasicAnimation,可以更明確地定義屬性如何改變動畫。
關鍵幀動畫,這是一種更復雜的顯式動畫類型,這里可以定義動畫的起點和終點,還可以定義某些幀之間的動畫。
網絡編程
原生API
TCP/IP簡介
HTTP協議簡介
REST
服務端API設計模式:使用Path指示資源;HTTP Verb表達操作。
API方法冪等( Idempotence)的概念:執行多次與執行一次效果一樣。
AFNetWorking
https://github.com/AFNetworking/AFNetworking
安裝:
CocoaPods:Podfile
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
pod 'AFNetworking', '~> 3.0'
Carthage:Cartfile
github "AFNetworking/AFNetworking" ~>3.0
Get方法請求
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"http://example.com/resources.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
Post請求
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *parameters = @{@"foo": @"bar"};
[manager POST:@"http://example.com/resources.json" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
AFNetworking 默認接受的數據類型是(在AFJSONResponseSerializer下):
self.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", nil];