1.size和center
如果想用size和center的組合去設置控件,這個size最好是從bounds中取,不用考慮調用順序;如果size從frame中獲得,一定要先設置了size,在設置center。
2.通知,[NSNotificationCenter defaultCenter]
- 1.發出通知
- 2.接收通知
- 3.移除通知
- 4.接收通知的方法是由發布通知的線程決定,在發布通知的線程中執行
- 5.一定要保證接收通知代碼在主線程調用
- 6.不管在哪個線程發送通知,都在接收通知的方法中跳轉到主線程
原因:不能在子線程接收通知,異步任務不會卡線程,不能保證是否先接收到通知
[[NSNotificationCenter defaultCenter] addObserverForName:postName object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification * _Nonnull note) {
// 主線程執行block
NSLog(@"%@",[NSThread currentThread]);
}];
3.frame和bounds
frame:以父控件左上角為原點的矩形
bounds:以自己的左上角為原點的矩形,修改bounds是針對控件里面的內容
frame和bounds都是描述一塊矩形
frame:描述可視范圍
bounds:描述可視范圍在內容中的矩形
bounds本質:修改的是內容原點位置
bounds:相對于父控件位置不變,相對于內容,位置改變
所有的子控件,都是相對于內容
UICollectionView 用代碼創建視圖 要自定義布局流時, 如果頁面有多個collectionView 也要創建多個UICollectionViewFlowLayout 與之對應. 否則會報錯
UICollectionView received layout attributes for a cell with an index path that does not exist: <NSIndexPath: 0xc000000000c00016> {length = 2, path = 0 - 6}
MAPKit
代理函數:
-(void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view 沒有調用,給annotation實例的title付了一個空格,即:annotation.title = @" ",注意,這里是空格,不是空值。
再次運行程序,能響應事件了,這應該是百度sdk中的一個小bug,因為google地圖不設置title也能正常顯示。
// 圓角
- (UIImage *)image:(CGFloat)radius size:(CGSize)size img:(UIImage *)img{
CGRect rect = (CGRect){0, 0, size};
UIGraphicsBeginImageContextWithOptions(rect.size, NO, [UIScreen mainScreen].scale);
CGContextAddPath(UIGraphicsGetCurrentContext(), [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:radius].CGPath);
CGContextClip(UIGraphicsGetCurrentContext());
[img drawInRect:rect];
CGContextDrawPath(UIGraphicsGetCurrentContext(), kCGPathFillStroke);
UIImage *im = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return im;
}
打印
#define DDLog(xx, ...) NSLog(@"%s(%d): " xx, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
Swift是否有運行時機制
http://makaidong.com/judy_luo/1/35704_10981245.html
地圖中不能在didUpdateUserLocation 頻繁調用這個動畫方法 會有閃退的危險 并且很難找出log日志(PS: 也就是說 這個方法時間單位不能重復多次的調用)
[self.recordMap setRegion:region animated:YES];