42.使用shareSDK分享到微博的時(shí)候壶熏,如果想使用微博客戶端分享,則添加如下代碼即可:
//允許使用微博客戶端分享
[shareParams SSDKEnableUseClientShare];
SSUIShareActionSheetController *sheet = [ShareSDK showShareActionSheet:nil
items:nil shareParams:shareParams onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {
switch (state) {
case SSDKResponseStateSuccess:
NSLog(@"分享成功!");
break;
case SSDKResponseStateFail:
NSLog(@"分享失敗!");
break;
case SSDKResponseStateCancel:
NSLog(@"取消分享!");
break;
default:
break;
}
}];
//加了這個(gè)方法之后可以不跳分享編輯界面服赎,直接點(diǎn)擊分享菜單里的選項(xiàng)跳轉(zhuǎn)到微博客戶端
[sheet.directSharePlatforms addObject:@(SSDKPlatformTypeSinaWeibo)];
小技能ps:想要分享一個(gè)url到微博,而且還想附加上圖片阶界,如果你此時(shí)沒有安裝微博客戶端摘盆,而且你把要分享的url寫到了url參數(shù)中,并設(shè)置分享類型為網(wǎng)頁奏黑,那么分享的時(shí)候會(huì)報(bào)錯(cuò)炊邦,導(dǎo)致分享不成功;解決辦法是:把要分享的url寫在text里面熟史,微博會(huì)自動(dòng)處理將你的url設(shè)為鏈接(分享類型改為SSDKContentTypeAuto)馁害。
43.讓imageView自適應(yīng)圖片自身的比例
imageView.contentMode = UIViewContentModeScaleAspectFit;
44.tableview滾動(dòng)到指定位置
NSIndexPath * lastCell = [NSIndexPath indexPathForRow:0 inSection:5];
[tableViews scrollToRowAtIndexPath:lastCell atScrollPosition:UITableViewScrollPositionTop animated:YES];
45.獲取線上版本號(hào)
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; [manager POST:@"https://itunes.apple.com/lookup?id=1160657486" parameters:nil success:^(AFHTTPRequestOperation * _Nonnull operation, id _Nonnull responseObject) {
NSArray *array = responseObject[@"results"]; NSDictionary *dict = [array lastObject]; NSLog(@"當(dāng)前版本為:%@", dict[@"version"]);
} failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
}];
46.iOS 8之后側(cè)滑(左滑)方法進(jìn)行了改進(jìn)具體方法是:
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
// 添加一個(gè)刪除按鈕
UITableViewRowAction *deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"刪除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
// 先移除數(shù)據(jù)源數(shù)據(jù)
[self.dataArray removeObjectAtIndex:indexPath.row];
// 再動(dòng)態(tài)刷新UITableView
[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
NSLog(@"刪除按鈕");
}];
UITableViewRowAction *topRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"置頂" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"置頂按鈕");
}];
/// 設(shè)置按鈕顏色,Normal默認(rèn)是灰色的蹂匹,Default默認(rèn)是紅色的
topRowAction.backgroundColor = [UIColor orangeColor];
UITableViewRowAction *cancelRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"取消關(guān)注" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"取消關(guān)注按鈕");
}];
return @[deleteRowAction,topRowAction,cancelRowAction];
}
使用該方法時(shí)注意:該方法只會(huì)在ios9之后的版本中才會(huì)有效碘菜,如果想在ios8以及ios8之前起作用的話必須額外加上下面這個(gè)代理方法:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
//方法內(nèi)可以什么都不寫,但必須加上限寞,否則側(cè)滑不起作用H绦ァ!履植!
}
49.iPhone X的屏幕navigationBar高度和statusBar高度和它之前的區(qū)別
iPhone X之前的蘋果:
navigationBar的frame為(0计雌,20,screenWidth玫霎,44)凿滤, statusbar的高度為20妈橄;
iPhone X:
navigationBar的frame為(0, 44, screenWidth, 44), statusbar的高度為44翁脆。
50.上拉加載更多回調(diào)調(diào)用多次的問題:
這種問題一般會(huì)出現(xiàn)在cell的高度是自適應(yīng)高度的情況下眷蚓,而且當(dāng)前運(yùn)行的手機(jī)系統(tǒng)為ios11!
總結(jié)其上拉的主要問題的原因是 tableViews :在iOS 11中默認(rèn)啟用Self-Sizing
這個(gè)應(yīng)該是UITableView最大的改變鹃祖。我們知道在iOS8引入Self-Sizing 之后溪椎,我們可以通過實(shí)現(xiàn)estimatedRowHeight相關(guān)的屬性來展示動(dòng)態(tài)的內(nèi)容,實(shí)現(xiàn)了estimatedRowHeight屬性后恬口,得到的初始contenSize是個(gè)估算值校读,是通過estimatedRowHeight 乘以 cell的個(gè)數(shù)得到的,并不是最終的contenSize祖能,只是當(dāng)前屏幕能夠顯示的cell個(gè)數(shù)歉秫,滑動(dòng)時(shí),tableView不停地得到新的cell养铸,更新自己的contenSize雁芙。
Self-Sizing在iOS11下是默認(rèn)開啟的,Headers, footers, and cells都默認(rèn)開啟Self-Sizing钞螟,所有estimated 高度默認(rèn)值從iOS11之前的 0 改變?yōu)閁ITableViewAutomaticDimension:
如果目前項(xiàng)目中沒有使用estimateRowHeight屬性兔甘,在iOS11的環(huán)境下就要注意了,因?yàn)殚_啟Self-Sizing之后鳞滨,tableView是使用estimateRowHeight屬性的洞焙,這樣就會(huì)造成contentSize和contentOffset值的變化,如果是有動(dòng)畫是觀察這兩個(gè)屬性的變化進(jìn)行的拯啦,就會(huì)造成動(dòng)畫的異常澡匪,因?yàn)樵诠浪阈懈邫C(jī)制下,contentSize的值是一點(diǎn)點(diǎn)地變化更新的褒链,所有cell顯示完后才是最終的contentSize值唁情。因?yàn)椴粫?huì)緩存正確的行高,tableView reloadData的時(shí)候甫匹,會(huì)重新計(jì)算contentSize甸鸟,就有可能會(huì)引起contentOffset的變化。
iOS11下不想使用Self-Sizing的話兵迅,可以通過以下方式關(guān)閉:
//添加以下代碼就能解決你的問題
self.tableView.estimatedRowHeight =0;
self.tableView.estimatedSectionHeaderHeight =0;
self.tableView.estimatedSectionFooterHeight =0;
注意?:這種問題未使用上面解決辦法而使用以下這種方法哀墓,只能解決留白問題,反而導(dǎo)致上拉刷新回彈問題
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
return nil;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
return nil;
}
總結(jié):經(jīng)測試最容易出現(xiàn)問題的是iOS11 plus機(jī)型喷兼,用出現(xiàn)問題的機(jī)型從App Store重新下載之前版本并不會(huì)出現(xiàn)問題,這些問題出現(xiàn)都是由于Xcode9運(yùn)行iOS11所造成的后雷。
參考文章:點(diǎn)我點(diǎn)我季惯。
51.automaticallyAdjustsScrollViewInsets(默認(rèn)為YES吠各,iOS 11之后棄用了該方法,改為contentInsetAdjustmentBehavior)
Specifies whether or not the view controller should automatically adjust its scroll view insets.
@property(nonatomic, assign) BOOL automaticallyAdjustsScrollViewInsets
Discussion
Default value isYES, which allows the view controller to adjust its scroll view insets in response to the screen areas consumed by the status bar, navigation bar, and toolbar or tab bar. Set toNOif you want to manage scroll view inset adjustments yourself, such as when there is more than one scroll view in the view hierarchy.
Availability
Available in iOS 7.0 and later.
Declared In
UIViewController.h
大體意思為:當(dāng)當(dāng)前試圖控制器的屏幕中存在導(dǎo)航條勉抓、狀態(tài)欄贾漏、工具欄和tabbar的時(shí)候,自動(dòng)布局它的scrollview藕筋,這種自動(dòng)調(diào)整是在ScrollView是其視圖添加的的第一個(gè)控件的時(shí)候,才會(huì)出現(xiàn)自動(dòng)調(diào)整的效果,如果在添加ScrollView之前添加了其他控件,不論控件的frame,自動(dòng)調(diào)整都會(huì)失效纵散。
ios11之后為何棄用該方法?猜測:automaticallyAdjustsScrollViewInsets是當(dāng)前試圖控制器的點(diǎn)方法隐圾,相對(duì)于scrollview本身的contentInsetAdjustmentBehavior方法來說不夠靈活伍掀,contentInsetAdjustmentBehavior可以對(duì)每個(gè)scrollview進(jìn)行設(shè)置。
52.第三方登錄之微信登錄獲取unionid
如果你用到了shareSDK或者友盟第三方登錄暇藏,網(wǎng)上有人說需要再調(diào)用微信提供的方法
https://api.weixin.qq.com/sns/userinfo?access_token=ACCESS_TOKEN&openid=OPENID
其實(shí)不需要蜜笤,只需要在回調(diào)里拿到 NSLog(@"unionid:%@",user.credential.rawData[@"unionid"]);就可以。(shareSDK例子)
53.獲取section指定行的frame
NSIndexPath *index = [NSIndexPath indexPathForRow:0 inSection:section];
UICollectionViewLayoutAttributes* attr = [self.rightCollectionView.collectionViewLayout layoutAttributesForSupplementaryViewOfKind:UICollectionElementKindSectionHeader atIndexPath:index];
NSLog(@"該行frame:%@",NSStringFromCGRect(attr.frame));
54.關(guān)于按鈕和label
1盐碱、如果把按鈕的userInteractionEnabled設(shè)為NO把兔,那么按鈕的點(diǎn)擊事件無響應(yīng);默認(rèn)為YES瓮顽;
2县好、如果把按鈕的userInteractionEnabled設(shè)為NO,即使未聲明該按鈕的方法暖混,程序執(zhí)行時(shí)缕贡,點(diǎn)擊按鈕也不會(huì)崩潰;
3儒恋、如果在一個(gè)label上添加點(diǎn)擊手勢善绎,然后把label的userInteractionEnabled設(shè)為NO,那么不會(huì)觸發(fā)手勢诫尽;默認(rèn)為NO禀酱;
55.關(guān)于runtime的交換方法實(shí)現(xiàn)
如果一個(gè)工程中有多個(gè)地方給label或者其他系統(tǒng)類添加catogry,并且交換了系統(tǒng)類的同一個(gè)方法實(shí)現(xiàn)牧嫉,如果兩個(gè)catogry交換后的方法名是一樣的剂跟,例如控制器的catogryA交換了控制器的方法viewDidLoad改為sd_viewDidLoad,然而控制器的catogryB也交換了控制器的方法viewDidLoad改為sd_viewDidLoad酣藻,這時(shí)候系統(tǒng)就不會(huì)執(zhí)行你自己寫的交換的方法實(shí)現(xiàn)曹洽;但是如果改了其中一個(gè)方法的名字,比如A的或者B的方法改為了sd_viewDidLoad之外的其他方法名辽剧,那么這兩個(gè)方法系統(tǒng)都會(huì)去執(zhí)行(先后順序未探索)送淆。