1.查看一段代碼的運行時間
#define STARTTIME NSDate *startTime = [NSDate date];
#define ENDTIME NSLog(@"Time: %f", -[startTime timeIntervalSinceNow]);
使用方法:
STARTTIME
do your work here
ENDTIME
2.在使用view的縮放的時候明郭,layer.border.width隨著view的放大丝里,會出現鋸齒化的問題例衍,解決這個問題需要設置這個屬性。
self.layer.allowsEdgeAntialiasing = YES;
3.一幅圖完美解釋UIImageView的UIContentMode
4.獲取當前最頂層的ViewController
通過最底層的ViewController依次向上尋找,直到找到最頂層的ViewController趣避,也就是從UIApplication的keyWindow的rootViewController開始尋找(如果有多個UIWindow則要考慮UIWindow的選擇問題。
在尋找的過程中新翎,要分別考慮當前ViewController是UITabBarController和UINavigationController的情況程帕,同時還要考慮到當前ViewController是否通過presentViewController:animated:completion:模態(tài)展示了其他ViewController住练。
實現代碼:
- (UIViewController *)topViewController {
UIViewController *resultVC;
resultVC = [self _topViewController:[[UIApplication sharedApplication].keyWindow rootViewController]];
while (resultVC.presentedViewController) {
resultVC = [self _topViewController:resultVC.presentedViewController];
}
return resultVC;
}
- (UIViewController *)_topViewController:(UIViewController *)vc {
if ([vc isKindOfClass:[UINavigationController class]]) {
return [self _topViewController:[(UINavigationController *)vc topViewController]];
} else if ([vc isKindOfClass:[UITabBarController class]]) {
return [self _topViewController:[(UITabBarController *)vc selectedViewController]];
} else {
return vc;
}
return nil;
}
使用方法:
UIViewController *topmostVC = [self topViewController];