事件沖突
- 解決scrollView的滑動(dòng)事件與子視圖按鈕事件沖突
self.scrollView.panGestureRecognizer.delaysTouchesBegan = YES;
2.根控制器TabBarViewController的setSelectedIndex進(jìn)行切換標(biāo)簽時(shí),從標(biāo)簽的導(dǎo)航棧中跳轉(zhuǎn)到其他標(biāo)簽時(shí)出現(xiàn)的問題,底部的tabbar隱藏?
因?yàn)樾枰萷op到導(dǎo)航棧的根視圖,然后再切到其他標(biāo)簽。
pop方法一定不要使用動(dòng)畫,設(shè)置成NO,因?yàn)閯?dòng)畫在標(biāo)簽切換時(shí),未完成就會(huì)出現(xiàn)問題。
原理:設(shè)置成YES,此時(shí)pop操作會(huì)在動(dòng)畫執(zhí)行完成之后,晚與標(biāo)簽切換,此時(shí)會(huì)隱藏掉tabbar。
[self.navigationController popToRootViewControllerAnimated:NO];
AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
[delegate.rootController setSelectedIndex:0];
3.使用Masonry進(jìn)行適配scrollview時(shí),因?yàn)闊o法通過CGSizeMake來設(shè)置它的contentSize,可以使用一個(gè)中間過渡view進(jìn)行處理。
4.滑動(dòng)時(shí)動(dòng)態(tài)獲取當(dāng)期顯示的是第幾個(gè)section,在方法- (void)scrollViewDidScroll:(UIScrollView *)scrollView中獲取
NSInteger section = [self.listView.tableView indexPathForRowAtPoint:CGPointMake(0, scrollView.contentOffset.y)].section;
5.更新單個(gè)cell時(shí),經(jīng)常將indexPath設(shè)置出錯(cuò),解決方式根據(jù)Section來進(jìn)行設(shè)置,既簡單有直觀,不容易出錯(cuò)
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0];
[self.listView.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
6.設(shè)置按鈕文字靠左對(duì)齊
// 設(shè)置UIButton字體居左顯示
repostBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
// 設(shè)置button的title就距左邊10個(gè)像素的距離。
repostBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
7.使用Masonry在給cell賦值時(shí),動(dòng)態(tài)更新lable的高度(使用了lable的寬度,而不是計(jì)算出來的寬度),發(fā)現(xiàn)frame沒有發(fā)生改變?
原因是:計(jì)算高度時(shí),lable的寬度為0,而不是真實(shí)的寬度。因?yàn)槭鞘褂肕asonry進(jìn)行的約束,然后查找原因發(fā)現(xiàn),使用Masonry進(jìn)行控件約束時(shí),不是立即調(diào)用layoutSubviews進(jìn)行布局更新,此時(shí)控件的frame都為0,需要調(diào)用layoutIfNeeded方法進(jìn)行布局更新,調(diào)用了系統(tǒng)的layoutIfNeeded方法之后,就會(huì)執(zhí)行l(wèi)ayoutSubviews進(jìn)行布局更新。
參考
8.編譯報(bào)錯(cuò)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
原因1:缺少支持的三方類庫。
9.collection布局
設(shè)置cell距離屏幕兩邊間隔的時(shí)候,一定要在設(shè)置size時(shí),寬度減去兩邊的間隔,然后再設(shè)置UIEdgeInsets屬性即可。
CGFloat margin = (15);
CGFloat width = (kScreenW - margin - 40)*0.5; // 40是距離屏幕的間隔
CGFloat height = width * (11/8.0);
layout.itemSize = CGSizeMake(width,height);
// 設(shè)置內(nèi)間距 top, left, bottom, right;
layout.sectionInset = UIEdgeInsetsMake(20, 20, 20, 20);
layout.minimumLineSpacing = margin; // 縱向Cell最小間距
layout.minimumInteritemSpacing = margin; // 橫向Cell最小間距
