本文整理 iOS 開發中常見的實用技巧,涵蓋表格視圖、手勢、鍵盤、導覽列、圖片拉伸、動畫與下拉刷新等主題。
可將表格的 tableFooterView 設為空白檢視:
self.tableView.tableFooterView = [[UIView alloc] init];

可將 interactivePopGestureRecognizer 的 delegate 設為自己,並在需要時處理手勢。
可嘗試關閉自動調整內縮:
self.automaticallyAdjustsScrollViewInsets = NO;
可使用 IQKeyboardManager 自動處理鍵盤遮擋與收合。
可使用 KMCGeigerCounter 監控 FPS,找出效能瓶頸。

可使用:
_myTableView.separatorInset = UIEdgeInsetsMake(0, 100, 0, 0);
可在 touchesBegan 中呼叫:
[self.view endEditing:YES];
可建立基底控制器,在檢視載入時設定背景。
可將控制項拖曳到程式碼中建立 IBOutlet,再修改約束。
可使用:
navigationController.hidesBarsOnSwipe = YES;
可使用:
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];

可使用 MagicalRecord 簡化操作。
可使用 CSStickyHeaderFlowLayout。
可根據 velocityInView: 的 x 與 y 分量判斷上下左右。
可使用:
stretchableImageWithLeftCapWidth:topCapHeight:
或改用較新的 resizableImageWithCapInsets:。

可使用 FLAnimatedImage。
可使用 SVPullToRefresh。
可設定表格的 tintColor。

可在 navigationController:willShowViewController:animated: 中重設狀態列樣式。
可將背景圖與陰影圖設為空白,並開啟 translucent。
可繼承 UITextField 並重寫 drawPlaceholderInRect:。
可持續閱讀 Stack Overflow、官方文件與社群範例,累積實戰經驗。