1荚坞、在UITextField中輸入內(nèi)容時(shí),內(nèi)容向下偏移
解決:UITextFiled在非編輯狀態(tài)只有一個(gè)子類(lèi)UITextFiledLabel菲盾,在編輯狀態(tài)時(shí)颓影,UITextField的子類(lèi)視圖發(fā)生了變化,有一個(gè)子類(lèi)視圖時(shí)UITextFieldEditor懒鉴,這個(gè)視圖繼承自UIScrollView 诡挂。 參考資料設(shè)置控制器的屬型automaticallyAdjustsScrollViewInsets = NO。
2临谱、創(chuàng)建xib時(shí)璃俗,從xib拖線生成對(duì)應(yīng)的屬性。在確定xib和對(duì)應(yīng)的類(lèi)進(jìn)行關(guān)聯(lián)之后悉默,拖線時(shí)無(wú)法生成對(duì)應(yīng)的屬性城豁。(Xcode有時(shí)就是不好使)
解決:在對(duì)應(yīng)類(lèi)的@interface @end 里手寫(xiě)IBOutlet屬性,反向拖線就好了
3抄课、在有導(dǎo)航欄的情況下設(shè)置狀態(tài)欄(statusBar)為lightContent時(shí)唱星,失去效果。
解決: self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
狀態(tài)欄的顏色會(huì)受到導(dǎo)航欄的樣式的影響跟磨。
4间聊、正確設(shè)置導(dǎo)航欄的標(biāo)題和標(biāo)簽欄標(biāo)題的正確姿勢(shì)
解決:
childController.navigationItem.title ; 設(shè)置導(dǎo)航欄的標(biāo)題
childController.tabBarItem.title;設(shè)置標(biāo)簽欄的標(biāo)題
childControllers.navigationController.tabBarItem.title;有導(dǎo)航欄控制器時(shí)設(shè)置標(biāo)簽欄的標(biāo)題
5、修改tableViewCell的accessoryView的樣色樣式(tintColor功能很強(qiáng)大吱晒,可以設(shè)置一些barTintColor甸饱,tintColor試一試第三條對(duì)狀態(tài)欄,導(dǎo)航欄的影響)
解決:tableView.tintColor = [UIColor redColor];
6仑濒、設(shè)置tableViewCell的分割線滿屏顯示
解決: tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
7叹话、使用xib設(shè)置tableView的headerView的時(shí)候,在顯示的時(shí)候headerView顯示不完整
解決: CLDetailHeaderView *headerView = [CLDetailHeaderView detailHeaderView];
// 計(jì)算headerView的大小墩瞳,設(shè)置好frame之后賦值給tableHeaderView才可以計(jì)算出合理大小的tableHeaderView
UIView *header = [[UIView alloc]initWithFrame:headerView.bounds];
[header addSubview:headerView];
headerView.foodModel = _foodModel;
self.tableView.tableHeaderView = header;```
#8驼壶、不顯示沒(méi)有內(nèi)容的tableViewCell
解答: // 8、取消多余的cell
self.tableView.tableFooterView = [[UIView alloc] init];
#9喉酌、在tableView或者collectionView瀏覽頁(yè)面的時(shí)候热凹,需要回到頂部的時(shí)候,在頁(yè)面上加上一個(gè)回到頂部的按鈕
解答: [self.tableView setContentOffset:CGPointZero animated:YES];
#10泪电、給系統(tǒng)的readonly屬性進(jìn)行修改般妙,一般會(huì)考慮使用KVC。比如自定義標(biāo)簽欄
CLTabBar *myTabBar = [[CLTabBar alloc] init];
[self setValue:myTabBar forKey:@"tabBar"]; // 給系統(tǒng)的tabBar屬性賦值進(jìn)行替換
-
(void)layoutSubviews{
[super layoutSubviews];
// 給tabBar的所有的tabBarButton添加點(diǎn)擊事件相速,然后在點(diǎn)擊事件中實(shí)現(xiàn)tabBarItem的動(dòng)畫(huà)效果
for (UIControl *tabBarButton in self.subviews) {
if ([tabBarButton isKindOfClass:NSClassFromString(@"UITabBarButton")]) {[tabBarButton addTarget:self action:@selector(tabBarButtonClick:) forControlEvents:UIControlEventTouchUpInside]; }
}
} (void)tabBarButtonClick:(UIControl *)tabBarButton
{
for (UIView *imageView in tabBarButton.subviews) {
NSLog(@"%@",tabBarButton.subviews); // 查找需要設(shè)置動(dòng)畫(huà)的對(duì)象
if ([imageView isKindOfClass:NSClassFromString(@"UITabBarSwappableImageView")]) {
//幀動(dòng)畫(huà)
CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
// 設(shè)置動(dòng)畫(huà)類(lèi)型為縮放動(dòng)畫(huà)
animation.keyPath = @"transform.scale";
animation.values = @[@1.0,@1.02,@0.9,@1.02,@0.90,@1.02,@1.0];
animation.duration = .8;
// 動(dòng)畫(huà)的進(jìn)行線性變化
animation.calculationMode = kCAAnimationCubic;
//把動(dòng)畫(huà)添加到需要?jiǎng)赢?huà)的tabBarItem的imageView的layer上
[imageView.layer addAnimation:animation forKey:nil];
}
}
}
#11碟渺、按鈕只有圖片的時(shí)候,設(shè)置按鈕大小和圖片等大
解決:button.bounds.size = button.currentBackgroundImage.size ;
#12突诬、給一個(gè)視圖添加背景圖片
解決:1苫拍、view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg"]]; // 純色圖片以平鋪的方式設(shè)置view的背景
2芜繁、view.layer.contents = (__bridge id)([UIImage imageNamed:@"bg"].CGImage);// 設(shè)置view的layer的內(nèi)容
#13、在自定義tabBar時(shí)用UIButton替換系統(tǒng)的UITabBarButton時(shí)绒极,需要UIButton在點(diǎn)擊的時(shí)候不要出現(xiàn)閃亮的情況
解決:重寫(xiě)一下UIButton的setHighlighted方法
// 去掉按鈕的高亮狀態(tài)
- (void)setHighlighted:(BOOL)highlighted{
在這個(gè)方法里面不要調(diào)用 super 否則寫(xiě)了相當(dāng)于沒(méi)寫(xiě)
}
#14骏令、保存按鈕的選中狀態(tài),需要添加一個(gè)按鈕屬性垄提。@property (nonatomic,strong) UIButton *selectedButton;
解答:
- (void)selectButton:(UIButton *)sender {
_selectedButton.selected = NO;
sender.selected = YES;
_selectedButton = sender;
}
#15榔袋、在代碼編寫(xiě)過(guò)程中發(fā)現(xiàn)變量名稱書(shū)寫(xiě)不合理,同時(shí)修改多個(gè)同名的變量名稱
![編輯技巧.gif](http://upload-images.jianshu.io/upload_images/2112071-f14565ed38739460.gif?imageMogr2/auto-orient/strip)
#16铡俐、Xcode8注釋失效
"這個(gè)是因?yàn)樘O(píng)果解決xcode ghost摘昌。把插件屏蔽了解決方法
命令運(yùn)行: sudo /usr/libexec/xpccachectl
然后必須重啟電腦后生效 "
或者
(1)查看 Xcode -> Preferences -> KeyBingdings
(2)我們可以找到 structure - AddDocumentation 這個(gè)就是添加注釋的 按照自己需求可以更改這里需要的快捷鍵,現(xiàn)在變成了 "Alt + Command + /"
(3)取消// 的注釋 的快捷鍵 也和之前我們常用的 "Command + /" 不一樣 如果 不喜歡 仍然可以改回來(lái)
(4)改好了退出 Preferences 到這里我的Xcode還是不好使 把電腦重啟后 就都重新正常使用了
#17、獲取手機(jī)電量高蜂,增強(qiáng)手機(jī)的續(xù)航能力,提高用戶體驗(yàn)罕容。 蘋(píng)果 在 iOS 9 中為 iPhone 添加了低電量模式 备恤。在此模式下,系統(tǒng)會(huì)通過(guò)禁用一些特性諸如電子郵件自動(dòng)獲取锦秒、后臺(tái)刷新露泊、Hey Siri等,來(lái)達(dá)到降低能耗的目的旅择。當(dāng)我們檢測(cè)到用戶開(kāi)啟了低電量模式惭笑,可以為用戶做一些小改變,來(lái)幫助用戶延長(zhǎng)電池續(xù)航生真。一般我們會(huì)停止后臺(tái)下載任務(wù)沉噩,停止定位服務(wù),停止網(wǎng)絡(luò)請(qǐng)求等柱蟀,來(lái)減少手機(jī)電池的電量消耗問(wèn)題川蒙。我們可以在控制器中監(jiān)控手機(jī)的電量,當(dāng)手機(jī)電量沒(méi)低于0.05的電量時(shí)就會(huì)發(fā)送通知长已,我們可以在接收到通知的時(shí)候進(jìn)行相應(yīng)的操作畜眨。
CGFloat battery = [UIDevice currentDevice].batteryLevel;// 0~1之間
// 在真機(jī)上必須要打開(kāi)允許電池監(jiān)聽(tīng)不然會(huì)認(rèn)為是模擬器 模擬器電量100%時(shí)會(huì)是-1
[UIDevice currentDevice].batteryMonitoringEnabled = YES;
#18、設(shè)置手機(jī)的旋轉(zhuǎn)方向
1术瓮、- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES 表示支持所有的方向 下面??的方法表示不支持向下的方向
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
2康聂、關(guān)于屏幕方向的枚舉
typedef enum {
UIInterfaceOrientationPortrait = UIDeviceOrientationPortrait, // 豎直方向
UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown, // 豎直向下
//because rotating the device to the left requires rotating the content to the right. 設(shè)備向左旋轉(zhuǎn) 設(shè)備顯示的內(nèi)容向右旋轉(zhuǎn)
UIInterfaceOrientationLandscapeLeft = UIDeviceOrientationLandscapeRight,// 橫屏向左
UIInterfaceOrientationLandscapeRight = UIDeviceOrientationLandscapeLeft橫屏向右
} UIInterfaceOrientation;
#19、在升級(jí)Cocoapods的時(shí)候報(bào)下面這個(gè)錯(cuò)誤的解決辦法:
![升級(jí)錯(cuò)誤信息.png](http://upload-images.jianshu.io/upload_images/2112071-58a83fd87730423d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
解決辦法:執(zhí)行下面的終端命令就好了
$ mkdir -p $HOME/Software/ruby
$ export GEM_HOME=$HOME/Software/ruby
$ gem install cocoapods
$ export PATH=$PATH:$HOME/Sofware/ruby/bin
$ pod --version // 查看pod版本號(hào) 驗(yàn)證是否升級(jí)成功