事件沖突
- 解決scrollView的滑動事件與子視圖按鈕事件沖突
self.scrollView.panGestureRecognizer.delaysTouchesBegan = YES;
2.根控制器TabBarViewController的setSelectedIndex進行切換標簽時,從標簽的導(dǎo)航棧中跳轉(zhuǎn)到其他標簽時出現(xiàn)的問題,底部的tabbar隱藏?
因為需要先pop到導(dǎo)航棧的根視圖,然后再切到其他標簽。
pop方法一定不要使用動畫,設(shè)置成NO,因為動畫在標簽切換時,未完成就會出現(xiàn)問題。
原理:設(shè)置成YES,此時pop操作會在動畫執(zhí)行完成之后,晚與標簽切換,此時會隱藏掉tabbar。
[self.navigationController popToRootViewControllerAnimated:NO];
AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
[delegate.rootController setSelectedIndex:0];
3.使用Masonry進行適配scrollview時,因為無法通過CGSizeMake來設(shè)置它的contentSize,可以使用一個中間過渡view進行處理。
4.滑動時動態(tài)獲取當期顯示的是第幾個section,在方法- (void)scrollViewDidScroll:(UIScrollView *)scrollView中獲取
NSInteger section = [self.listView.tableView indexPathForRowAtPoint:CGPointMake(0, scrollView.contentOffset.y)].section;
5.更新單個cell時,經(jīng)常將indexPath設(shè)置出錯,解決方式根據(jù)Section來進行設(shè)置,既簡單有直觀,不容易出錯
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0];
[self.listView.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
6.設(shè)置按鈕文字靠左對齊
// 設(shè)置UIButton字體居左顯示
repostBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
// 設(shè)置button的title就距左邊10個像素的距離。
repostBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
7.使用Masonry在給cell賦值時,動態(tài)更新lable的高度(使用了lable的寬度,而不是計算出來的寬度),發(fā)現(xiàn)frame沒有發(fā)生改變?
原因是:計算高度時,lable的寬度為0,而不是真實的寬度。因為是使用Masonry進行的約束,然后查找原因發(fā)現(xiàn),使用Masonry進行控件約束時,不是立即調(diào)用layoutSubviews進行布局更新,此時控件的frame都為0,需要調(diào)用layoutIfNeeded方法進行布局更新,調(diào)用了系統(tǒng)的layoutIfNeeded方法之后,就會執(zhí)行l(wèi)ayoutSubviews進行布局更新。
參考
8.編譯報錯
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è)置size時,寬度減去兩邊的間隔,然后再設(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最小間距
