CoreAnimation示例
? ? CABasicAnimation* folat = [CABasicAnimation animationWithKeyPath:@"opacity"];
??? folat.fillMode = kCAFillModeBackwards;
??? folat.duration = 0.5;
??? folat.beginTime = CACurrentMediaTime()+1.1;
??? folat.fromValue = @(0);
??? folat.toValue = @(1);
??? [v1.layer addAnimation:folat forKey:nil];
-(void)animateLocate:(UIImageView*)view{
??? float speed = 10.0/self.view.bounds.size.width;
??? float dur = (self.view.bounds.size.width-view.frame.origin.x)*speed;
??? [UIView animateWithDuration:dur delay:0.1 options:UIViewAnimationOptionCurveEaseOut animations:^{
??????? CGRect rc = view.frame;
??????? rc.origin.x = self.view.bounds.size.width;
??????? view.frame = rc;
??? } completion:^(BOOL fin){
??????? CGRect rc = view.frame;
??????? rc.origin.x = 0;
??????? view.frame = rc;
??????? [self animateLocate:view];
??? }];
}
Masonry的使用
我希望兩個等寬高的紅色方塊能夠在屏幕旋轉(zhuǎn)的時候,間距等比例縮放半哟,它們的相對位置是固定的,絕對位置隨著屏幕的寬改變而改變
//代碼中View的順序與圖中從左到右的View的順序一致
//例子中,唯一不確定的就是灰色View的寬度,我們先把確定的約束給一個一個的添加上來
//灰1左間距画株、高度冕房、垂直位置(因為和紅1底部對齊)是確定的,添加約束
[gray1 mas_makeConstraints:^(MASConstraintMaker *make{????????
make.height.mas_equalTo(20);????????make.leading.equalTo(self.view.mas_leading).offset(0);????????
make.bottom.equalTo(red1.mas_bottom);????}];
//紅1婶博,寬高、左間距荧飞、底間距是確定的凡人,添加約束?
[red1 mas_makeConstraints:^(MASConstraintMaker *make) {????????
make.width.mas_equalTo(100);????????make.height.mas_equalTo(50);????????make.left.equalTo(gray1.mas_right);????????
make.bottom.equalTo(self.view.mas_bottom).offset(-50);????}];
//灰2,左間距叹阔、高度挠轴、垂直位置是確定的,寬度要與灰1一致耳幢,是為了能均勻填充岸晦,添加約束?
[gray2 mas_makeConstraints:^(MASConstraintMaker *make) {????????
make.height.and.width.equalTo(gray1);????????make.leading.equalTo(red1.mas_right);????????
make.bottom.equalTo(red1.mas_bottom);????}];
//紅2,寬高、左間距启上、底間距是確定的邢隧,添加約束?
[red2 mas_makeConstraints:^(MASConstraintMaker *make) {????????
make.height.and.width.equalTo(red1);????????make.leading.equalTo(gray2.mas_right);????????
make.bottom.equalTo(red1.mas_bottom);????}];
//灰3,左間距冈在、右間距府框、高度、垂直位置是確定的讥邻,添加約束?
[gray3 mas_makeConstraints:^(MASConstraintMaker *make) {????????
make.height.and.width.equalTo(gray1);????????make.leading.equalTo(red2.mas_right);????????
make.trailing.equalTo(self.view.mas_right);????????make.bottom.equalTo(red1.mas_bottom);???? }];
其中 迫靖,make.left.equalTo(redView.mas_right).offset(20).priority(250);
priority設(shè)置優(yōu)先級,默認(rèn)是1000兴使,此場景用于中間的控件可能被隱藏或移除的情況
Runloop Mode
NSDefaultRunLoopMode
UITrackingRunLoopModes
NSRunLoopCommonModes
performSelector關(guān)于內(nèi)存管理的執(zhí)行原理是這樣的執(zhí)行 [self performSelector:@selector(method1:) withObject:self.tableLayer afterDelay:3]; 的時候系宜,系統(tǒng)會將tableLayer的引用計數(shù)加1,執(zhí)行完這個方法時发魄,還會將tableLayer的引用計數(shù)減1盹牧,由于延遲這時tableLayer的引用計數(shù)沒有減少到0,也就導(dǎo)致了切換場景dealloc方法沒有被調(diào)用励幼,出現(xiàn)了內(nèi)存泄露汰寓。
利用如下函數(shù):[NSObject cancelPreviousPerformRequestsWithTarget:self]
A repeating timer reschedules itself based on the scheduled firing time, not the actual firing time. For example, if a timer is scheduled to fire at a particular time and every 5 seconds after that, the scheduled firing time will always fall on the original 5 second time intervals, even if the actual firing time gets delayed. If the firing time is delayed so far that it passes one or more of the scheduled firing times, the timer is fired only once for that time period; the timer is then rescheduled, after firing, for the next scheduled firing time in the future.
注意:NSTimer使用最好加到主線程runloop中去,并且使用NSRunLoopCommonModes
關(guān)于library 苹粟,framework & CocoaPod
You may be wondering, “What’s the difference between a library, a framework and a CocoaPod?” And trust me, it’s okay if you find the whole thing a touch confusing!
A CocoaPod, or “pod” for short, is a general term for either a library or framework that’s added to your project by using the CocoaPods tool.
iOS 8 introduced dynamic frameworks, and these allow code, images and other assets to be bundled together. Prior to iOS 8, CocoaPods were created as static libraries, which are just “fat” binaries. This means they contain several code instruction sets (e.g. i386 for the simulator, armv7 for devices, etc.), but they aren’t allowed to contain any resources such as images or assets.
Another important difference is dynamic frameworks have namespace classes and static libraries don’t. So, if you had two classes called MyTestClass in different static libraries within a single project, Xcode would not be able to build the project because it would fail to link correctly citing duplicate symbols. However, Xcode is perfectly happy building a project that has two classes with the same name in different frameworks.
Why does this matter? Unlike Objective-C, the standard Swift runtime libraries aren’t included in iOS! This means your framework must include the necessary Swift runtime libraries. As a consequence, pods written in Swift must be created as dynamic frameworks. If Apple allowed Swift static libraries, it would cause duplicate symbols across different libraries that use the same standard runtime dependencies.
Alcatraz
在xcode8+安裝如下:
sudo gem install update_xcode_plugins
update_xcode_plugins??先備份xcode 然后
update_xcode_plugins --unsign??得到unsigned xcode
安裝Alcatraz后有滑,推薦使用插件
FuzzyAutoComplete 編碼提示
VVDocumenter-Xcode 快速注釋
KSImageNamed imagenamed 快捷找到圖片資源
instruments使用time profiler注意事項
1.當(dāng)點(diǎn)擊Time Profiler應(yīng)用程序開始運(yùn)行后.就能獲取到整個應(yīng)用程序運(yùn)行消耗時間分布和百分比.為了保證數(shù)據(jù)分析在統(tǒng)一使用場景真實(shí)行有如下點(diǎn)需要注意:
在開始進(jìn)行應(yīng)用程序性能分析的時候,一定要使用真機(jī),模擬器運(yùn)行在Mac上,然而Mac上的CPU往往比iOS設(shè)備要快嵌削。相反毛好,Mac上的GPU和iOS設(shè)備的完全不一樣,模擬器不得已要在軟件層面(CPU)模擬設(shè)備的GPU苛秕,這意味著GPU相關(guān)的操作在模擬器上運(yùn)行的更慢肌访,尤其是使用CAEAGLLayer來寫一些OpenGL的代碼時候. 這就導(dǎo)致模擬器性能數(shù)據(jù)和用戶真機(jī)使用性能數(shù)據(jù)相去甚遠(yuǎn).
2.另外在開始性能分析前另外一件重要的事情是,應(yīng)用程序運(yùn)行一定要發(fā)布配置 而不是調(diào)試配置.
在發(fā)布環(huán)境打包的時候艇劫,編譯器會引入一系列提高性能的優(yōu)化吼驶,例如去掉調(diào)試符號或者移除并重新組織代碼.另iOS引入一種"Watch Dog"[看門狗]機(jī)制.不同的場景下,“看門狗”會監(jiān)測應(yīng)用的性能店煞。如果超出了該場景所規(guī)定的運(yùn)行時間蟹演,“看門狗”就會強(qiáng)制終結(jié)這個應(yīng)用的進(jìn)程.開發(fā)者可以crashlog看到對應(yīng)的日志.但Xcode在調(diào)試配置下會禁用"Watch Dog"
幾種配置可選項:
Separate by Thread(建議選擇):通過線程分類來查看那些線程占用CPU最多。
Invert Call Tree(不建議選擇):調(diào)用樹倒返過來浅缸,將習(xí)慣性的從根向下一級一級的顯示轨帜,如選上就會反過來從最底層調(diào)用向一級一級的顯示魄咕。如果想要查看那個方法調(diào)用為最深時使用會更方便些衩椒。
Hide Missing Symbols(建議選擇):隱藏丟失的符號,比如應(yīng)用或者系統(tǒng)的dSYM文件找不到的話,在詳情面板上是看不到方法名的毛萌,只能看一些讀不懂的十六進(jìn)值苟弛,所以對我們來說是沒有意義的,去掉了會使閱讀更清楚些阁将。
Hide System Libraries(建議選擇):選上它只會展示與應(yīng)用有關(guān)的符號信息膏秫,一般情況下我們只關(guān)心自己寫的代碼所需的耗時,而不關(guān)心系統(tǒng)庫的CPU耗時做盅。
Flatten Recursion(一般不選):選上它會將調(diào)用棧里遞歸函數(shù)作為一個入口缤削。
Top Functions(可選):選上它會將最耗時的函數(shù)降序排列,而這種耗時是累加的吹榴,比如A調(diào)用了B亭敢,那么A的耗時數(shù)是會包含B的耗時數(shù)。