UI調(diào)試工具
清理啟動(dòng)頁緩存
NSString * filePath = NSHomeDirectory().mc_append(@"/Library/SplashBoard");
[[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
imagemagick 圖片壓縮 修改hash
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install imagemagick
find . -iname "*.png" -exec echo {} \; -exec convert {} {} \;
靜態(tài)方法
static void SimpleObjectExample() {
YYBook *book = [YYBook modelWithJSON:@" \
{ \
\"name\": \"Harry Potter\", \
\"pages\": 512, \
\"publishDate\": \"2010-01-01\" \
}"];
NSString *bookJSON = [book modelToJSONString];
NSLog(@"Book: %@", bookJSON);
}
布局
HandyFrame
隊(duì)列
dispatch_queue_t queue = dispatch_queue_create("com.ios.refresh", DISPATCH_QUEUE_CONCURRENT);
dispatch_group_t group = dispatch_group_create();
dispatch_group_enter(group);
[self ask_clubInfo:^{
dispatch_group_leave(group);
}];
dispatch_group_notify(group, queue, ^{
});
信號量
dispatch_semaphore_t semaphore = dispatch_semaphore_create(1);
dispatch_queue_t quene = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
for (......) {
dispatch_async(quene, ^{
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
do....
dispatch_semaphore_signal(semaphore);
});
}
dispatch_async(quene, ^{
//最后執(zhí)行
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
if(finishBlock)
{
finishBlock(YES,dataList);
}
dispatch_semaphore_signal(semaphore);
});
屬性的synthesize dynamic
1、@property有兩個(gè)對應(yīng)的詞,一個(gè)是@synthesize,一個(gè)是@dynamic。如果@synthesize和@dynamic都沒寫,那么默認(rèn)的就是@syntheszie var = _var;
2、@synthesize的語義是如果你沒有手動(dòng)實(shí)現(xiàn)setter方法和getter方法,那么編譯器會自動(dòng)為你加上這兩個(gè)方法。
3、@dynamic告訴編譯器,屬性的setter與getter方法由用戶自己實(shí)現(xiàn),不自動(dòng)生成。(當(dāng)然對于readonly的屬性只需提供getter即可)。假如一個(gè)屬性被聲明為@dynamic var,然后你沒有提供@setter方法和@getter方法,編譯的時(shí)候沒問題,但是當(dāng)程序運(yùn)行到instance.var =someVar,由于缺setter方法會導(dǎo)致程序崩潰;或者當(dāng)運(yùn)行到 someVar = var時(shí),由于缺getter方法同樣會導(dǎo)致崩潰。編譯時(shí)沒問題,運(yùn)行時(shí)才執(zhí)行相應(yīng)的方法,這就是所謂的動(dòng)態(tài)綁定。
結(jié)構(gòu)體定義
struct SpaceImg{
CGFloat img1_left;
CGFloat img1_right;
CGFloat img2_left;
CGFloat img2_right;
};
typedef struct SpaceImg SpaceImg;
XCode插件
系統(tǒng)音效
Block定義
int(^myBlock)(int) = ^(int num){
return num * 7;
};
// 如果沒有參數(shù)列表,在賦值時(shí)參數(shù)列表可以省略
void(^aVoidBlock)() = ^{
NSLog(@"I am a aVoidBlock");
};
添加QQ群助手
https://qun.qq.com/join.html?has_onekey=1
表格刪除添加cell的時(shí)候跳動(dòng)問題
iOS11 self-sizing 默認(rèn)開啟 會自動(dòng)計(jì)算cell的高度 contentsize和contentOffset會發(fā)生變化
self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;
部分圓角
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10, 10)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = rect;
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
iOS11 上scrollview布局向下偏移問題
automaticallyAdjustsScrollViewInsets 方法有調(diào)整
if (@available(iOS 11.0, *)) {
self.scrollV.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
} else {
self.automaticallyAdjustsScrollViewInsets = NO;
}
CAAnimation 的keypath
transform.scale = 比例轉(zhuǎn)換
transform.scale.x = 寬的比例轉(zhuǎn)換
transform.scale.y = 高的比例轉(zhuǎn)換
transform.rotation.z = 平面圖的旋轉(zhuǎn)
opacity = 透明度
margin=邊框間隔?
zPosition = 平面圖的位置
backgroundColor = 背景色
cornerRadius = layer的角度
borderWidth = 邊框?qū)挾?
contents = 內(nèi)容?
bounds = 大小?
contentsRect = 內(nèi)容矩形
frame = 位置
hidden = 隱藏
mask = 標(biāo)記
maskToBounds
position = 位置
shadowOffset = 陰影偏移?
shadowColor = 陰影顏色
shadowRadius = 陰影角度
動(dòng)畫結(jié)束狀態(tài)不變
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards;
監(jiān)聽動(dòng)畫過程frame
// 監(jiān)聽MyView
- (void)startWatchMyView {
[self stopWatchMyView];
self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(watchMyViewAction)];
[self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
}
- (void)watchMyViewAction {
CALayer *presentationLayer = self.myView.layer.presentationLayer;
[self handleMaskViewWithMyViewFrame:presentationLayer.frame];
}
// 停止監(jiān)聽MyView
- (void)stopWatchMyView {
[self.displayLink invalidate];
self.displayLink = nil;
[self watchMyViewAction];
}
- (void)handleMaskViewWithMyViewFrame:(CGRect)myFrame {
// 下面是根據(jù)myFrame 進(jìn)行其他相關(guān)view的繪制
[self.myView setNeedsDisplay];
// mask處理overlayView
self.overlayView.maskFrame = myFrame;
[self.overlayView setNeedsDisplay];
}
獲取啟動(dòng)頁圖片
+ (UIImage *)getTheLaunchImage
{
CGSize viewSize = [UIScreen mainScreen].bounds.size;
NSString *viewOrientation = nil;
if (([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortraitUpsideDown) || ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait)) {
viewOrientation = @"Portrait";
} else {
viewOrientation = @"Landscape";
}
NSString *launchImage = nil;
NSArray* imagesDict = [[[NSBundle mainBundle] infoDictionary] valueForKey:@"UILaunchImages"];
for (NSDictionary* dict in imagesDict)
{
CGSize imageSize = CGSizeFromString(dict[@"UILaunchImageSize"]);
if (CGSizeEqualToSize(imageSize, viewSize) && [viewOrientation isEqualToString:dict[@"UILaunchImageOrientation"]])
{
launchImage = dict[@"UILaunchImageName"];
}
}
return [UIImage imageNamed:launchImage];
}