開(kāi)發(fā)知識(shí)匯總
關(guān)鍵字const
的位置
const意味著”只讀”,分析下面的含義
const int a;
int const a;
// 前兩個(gè)的作用是一樣迫筑,a是一個(gè)常整型數(shù)宪赶。
const int *a;
// 第三個(gè)意味著a是一個(gè)指向常整型數(shù)的指針(整型數(shù)是不可修改的,但指針可以)
int * const a;
// 第四個(gè)意思a是一個(gè)指向整型數(shù)的常指針(指針指向的整型數(shù)是可以修改的脯燃,但指針是不可修改的)
int const * const a;
// a是一個(gè)指向常整型數(shù)的常指針(指針指向的整型數(shù)是不可修改的搂妻,同時(shí)指針也是不可修改的)。表示a是一個(gè)指針常量辕棚,初始化的時(shí)候必須固定指向一個(gè)int常量或者int變量欲主,之后就不能再指向別的地方了,它總是把它所指向的目標(biāo)當(dāng)作一個(gè)int常量逝嚎。也可以寫(xiě)成const int* const a;含義相同扁瓢。
滑動(dòng)隱藏導(dǎo)航欄(navigation bar)
navigationController.hidesBarsOnSwipe = YES;
Navigationbar變成透明而不模糊(navigation bar)
[self.navigationController.navigationBar setBackgroundImage:[UIImage new]
forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar .shadowImage = [UIImage new];
self.navigationController.navigationBar .translucent = YES;
仿系統(tǒng)彈出出動(dòng)畫(huà)(漸變大)
必須把changeOutView先添加到父視圖上去
+(void)exChangeOut:(UIView *)changeOutView dur:(CFTimeInterval)dur{ CAKeyframeAnimation * animation; animation = [CAKeyframeAnimation animationWithKeyPath:@"transform"];
animation.duration = dur;
animation.delegate = self;
animation.removedOnCompletion = NO;
animation.fillMode = kCAFillModeForwards; NSMutableArray *values = [NSMutableArray array];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.1, 0.1, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.2, 1.2, 1.0)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9, 0.9, 0.9)]];
[values addObject:[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)]];
animation.values = values; animation.timingFunction = [CAMediaTimingFunction functionWithName: @"easeInEaseOut"];
[changeOutView.layer addAnimation:animation forKey:nil];
}
關(guān)于View
view.layer.shouldRasterize = YES;//去除View鋸齒
view.layer.shadowColor //投影顏色
view.layer.shadowOffset //投影偏移量
view.layer.shadowRadius //投影弧度
view.layer.shadowPath //投影路徑
#設(shè)置View 的圓角等樣式都是設(shè)置 view.layer 的屬性
關(guān)于導(dǎo)航欄
//設(shè)置導(dǎo)航欄顏色(全局設(shè)置)
[[UINavigationBar appearance] setBarTintColor:UIColorFromRGB(0x067AB5)];
//設(shè)置導(dǎo)航欄背景圖片
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav_bg.png"] forBarMetrics:UIBarMetricsDefault];
//自定義返回按鈕圖片(默認(rèn)狀態(tài))
[[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:@"back_btn.png"]];
//自定義返回按鈕圖片(按下?tīng)顟B(tài))
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"back_btn.png"]];
#設(shè)置導(dǎo)航返回按鈕顏色(除了返回按鈕,tintColor屬性會(huì)影響到所有按鈕標(biāo)題和圖片懈糯。)
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
//修改導(dǎo)航欄的返回按鈕顏色
self.navigationController.tintcolor = color
//設(shè)置導(dǎo)航欄標(biāo)題的風(fēng)格(dictionary key
UITextAttributeFont – 字體key
UITextAttributeTextColor – 文字顏色key
UITextAttributeTextShadowColor – 文字陰影色key
UITextAttributeTextShadowOffset – 文字陰影偏移量key)
UITextAttributeFont 字體大小
[[UINavigationBar appearance] setTitleTextAttributes:(NSDictionary<NSString *,id> * _Nullable)]
//自定義導(dǎo)航欄View (一般用于設(shè)置圖片涤妒,或者按鈕)
self.navigationItem.titleView = view
版本號(hào)比較
if ([string1 compare:@"string2"] == 0) {
//版本相等
}
禁止鍵盤彈出時(shí)UIWebView自動(dòng)滑動(dòng)
webview.scrollView.delegate=self;
-(UIView*)viewForZoomingInScrollView:(UIScrollView*)scrollView {
return nil;
}
有時(shí)候layer.cornerRadius并不能滿足需求,自己實(shí)現(xiàn)drawRect又太麻煩赚哗,怎么辦她紫?
- (void)dwMakeBottomRoundCornerWithRadius:(CGFloat)radius view:(UIView *)views
{
CGSize size = views.frame.size;
CAShapeLayer *shapeLayer = [CAShapeLayer layer];
[shapeLayer setFillColor:[[UIColor whiteColor] CGColor]];
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, size.width - radius, size.height);
CGPathAddArc(path, NULL, size.width-radius, size.height-radius, radius, M_PI/2, 0.0, YES);
CGPathAddLineToPoint(path, NULL, size.width, 0.0);
CGPathAddLineToPoint(path, NULL, 0.0, 0.0);
CGPathAddLineToPoint(path, NULL, 0.0, size.height - radius);
CGPathAddArc(path, NULL, radius, size.height - radius, radius, M_PI, M_PI/2, YES);
CGPathCloseSubpath(path);
[shapeLayer setPath:path];
CFRelease(path);
views.layer.mask = shapeLayer;//layer的mask,顧名思義屿储,是種位掩蔽贿讹,在shapeLayer的填充區(qū)域中,alpha值不為零的部分够掠,self會(huì)被繪制民褂;alpha值為零的部分,self不會(huì)被繪制,甚至不會(huì)響應(yīng)touch
}
drawrect 畫(huà)線
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
/*NO.1畫(huà)一條線
CGContextSetRGBStrokeColor(context, 0.5, 0.5, 0.5, 0.5);//線條顏色
CGContextMoveToPoint(context, 20, 20);
CGContextAddLineToPoint(context, 200,20);
CGContextStrokePath(context);
*/
/*NO.2寫(xiě)文字
CGContextSetLineWidth(context, 1.0);
CGContextSetRGBFillColor (context, 0.5, 0.5, 0.5, 0.5);
UIFont *font = [UIFont boldSystemFontOfSize:18.0];
[@"公司:北京中軟科技股份有限公司\n部門:ERP事業(yè)部\n姓名:McLiang" drawInRect:CGRectMake(20, 40, 280, 300) withFont:font];
*/
/*NO.3畫(huà)一個(gè)正方形圖形 沒(méi)有邊框
CGContextSetRGBFillColor(context, 0, 0.25, 0, 0.5);
CGContextFillRect(context, CGRectMake(2, 2, 270, 270));
CGContextStrokePath(context);
*/
/*NO.4畫(huà)正方形邊框
CGContextSetRGBStrokeColor(context, 0.5, 0.5, 0.5, 0.5);//線條顏色
CGContextSetLineWidth(context, 2.0);
CGContextAddRect(context, CGRectMake(2, 2, 270, 270));
CGContextStrokePath(context);
*/
/*NO.5畫(huà)方形背景顏色
CGContextTranslateCTM(context, 0.0f, self.bounds.size.height);
CGContextScaleCTM(context, 1.0f, -1.0f);
UIGraphicsPushContext(context);
CGContextSetLineWidth(context,320);
CGContextSetRGBStrokeColor(context, 250.0/255, 250.0/255, 210.0/255, 1.0);
CGContextStrokeRect(context, CGRectMake(0, 0, 320, 460));
UIGraphicsPopContext();
*/
/*NO.6橢圓
CGRect aRect= CGRectMake(80, 80, 160, 100);
CGContextSetRGBStrokeColor(context, 0.6, 0.9, 0, 1.0);
CGContextSetLineWidth(context, 3.0);
CGContextAddEllipseInRect(context, aRect); //橢圓
CGContextDrawPath(context, kCGPathStroke);
*/
/*NO.7
CGContextBeginPath(context);
CGContextSetRGBStrokeColor(context, 0, 0, 1, 1);
CGContextMoveToPoint(context, 100, 100);
CGContextAddArcToPoint(context, 50, 100, 50, 150, 50);
CGContextStrokePath(context);
*/
/*NO.8漸變
CGContextClip(context);
CGColorSpaceRef rgb = CGColorSpaceCreateDeviceRGB();
CGFloat colors[] =
{
204.0 / 255.0, 224.0 / 255.0, 244.0 / 255.0, 1.00,
29.0 / 255.0, 156.0 / 255.0, 215.0 / 255.0, 1.00,
0.0 / 255.0, 50.0 / 255.0, 126.0 / 255.0, 1.00,
};
CGGradientRef gradient = CGGradientCreateWithColorComponents
(rgb, colors, NULL, sizeof(colors)/(sizeof(colors[0])*4));
CGColorSpaceRelease(rgb);
CGContextDrawLinearGradient(context, gradient,CGPointMake
(0.0,0.0) ,CGPointMake(0.0,self.frame.size.height),
kCGGradientDrawsBeforeStartLocation);
*/
/* NO.9四條線畫(huà)一個(gè)正方形
//畫(huà)線
UIColor *aColor = [UIColor colorWithRed:0 green:1.0 blue:0 alpha:0];
CGContextSetRGBStrokeColor(context, 1.0, 0, 0, 1.0);
CGContextSetFillColorWithColor(context, aColor.CGColor);
CGContextSetLineWidth(context, 4.0);
CGPoint aPoints[5];
aPoints[0] =CGPointMake(60, 60);
aPoints[1] =CGPointMake(260, 60);
aPoints[2] =CGPointMake(260, 300);
aPoints[3] =CGPointMake(60, 300);
aPoints[4] =CGPointMake(60, 60);
CGContextAddLines(context, aPoints, 5);
CGContextDrawPath(context, kCGPathStroke); //開(kāi)始畫(huà)線
*/
/* NO.10
UIColor *aColor = [UIColor colorWithRed:0 green:1.0 blue:0 alpha:0];
CGContextSetRGBStrokeColor(context, 1.0, 0, 0, 1.0);
CGContextSetFillColorWithColor(context, aColor.CGColor);
//橢圓
CGRect aRect= CGRectMake(80, 80, 160, 100);
CGContextSetRGBStrokeColor(context, 0.6, 0.9, 0, 1.0);
CGContextSetLineWidth(context, 3.0);
CGContextSetFillColorWithColor(context, aColor.CGColor);
CGContextAddRect(context, rect); //矩形
CGContextAddEllipseInRect(context, aRect); //橢圓
CGContextDrawPath(context, kCGPathStroke);
*/
/* NO.11
畫(huà)一個(gè)實(shí)心的圓
CGContextFillEllipseInRect(context, CGRectMake(95, 95, 100.0, 100));
*/
/*NO.12
畫(huà)一個(gè)菱形
CGContextSetLineWidth(context, 2.0);
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGContextMoveToPoint(context, 100, 100);
CGContextAddLineToPoint(context, 150, 150);
CGContextAddLineToPoint(context, 100, 200);
CGContextAddLineToPoint(context, 50, 150);
CGContextAddLineToPoint(context, 100, 100);
CGContextStrokePath(context);
*/
/*NO.13 畫(huà)矩形
CGContextSetLineWidth(context, 2.0);
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGRect rectangle = CGRectMake(60,170,200,80);
CGContextAddRect(context, rectangle);
CGContextStrokePath(context);
*/
/*橢圓
CGContextSetLineWidth(context, 2.0);
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGRect rectangle = CGRectMake(60,170,200,80);
CGContextAddEllipseInRect(context, rectangle);
CGContextStrokePath(context);
*/
/*用紅色填充了一段路徑:
CGContextMoveToPoint(context, 100, 100);
CGContextAddLineToPoint(context, 150, 150);
CGContextAddLineToPoint(context, 100, 200);
CGContextAddLineToPoint(context, 50, 150);
CGContextAddLineToPoint(context, 100, 100);
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
CGContextFillPath(context);
*/
/*填充一個(gè)藍(lán)色邊的紅色矩形
CGContextSetLineWidth(context, 2.0);
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGRect rectangle = CGRectMake(60,170,200,80);
CGContextAddRect(context, rectangle);
CGContextStrokePath(context);
CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
CGContextFillRect(context, rectangle);
*/
/*畫(huà)弧
//弧線的是通過(guò)指定兩個(gè)切點(diǎn)赊堪,還有角度面殖,調(diào)用CGContextAddArcToPoint()繪制
CGContextSetLineWidth(context, 2.0);
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGContextMoveToPoint(context, 100, 100);
CGContextAddArcToPoint(context, 100,200, 300,200, 100);
CGContextStrokePath(context);
*/
/*
繪制貝茲曲線
//貝茲曲線是通過(guò)移動(dòng)一個(gè)起始點(diǎn),然后通過(guò)兩個(gè)控制點(diǎn),還有一個(gè)中止點(diǎn)哭廉,調(diào)用CGContextAddCurveToPoint() 函數(shù)繪制
CGContextSetLineWidth(context, 2.0);
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGContextMoveToPoint(context, 10, 10);
CGContextAddCurveToPoint(context, 0, 50, 300, 250, 300, 400);
CGContextStrokePath(context);
*/
/*繪制二次貝茲曲線
CGContextSetLineWidth(context, 2.0);
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGContextMoveToPoint(context, 10, 200);
CGContextAddQuadCurveToPoint(context, 150, 10, 300, 200);
CGContextStrokePath(context);
*/
/*繪制虛線
CGContextSetLineWidth(context, 5.0);
CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
CGFloat dashArray[] = {2,6,4,2};
CGContextSetLineDash(context, 3, dashArray, 4);//跳過(guò)3個(gè)再畫(huà)虛線脊僚,所以剛開(kāi)始有6-(3-2)=5個(gè)虛點(diǎn)
CGContextMoveToPoint(context, 10, 200);
CGContextAddQuadCurveToPoint(context, 150, 10, 300, 200);
CGContextStrokePath(context);
*/
/*繪制圖片
NSString* imagePath = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"];
UIImage* myImageObj = [[UIImage alloc] initWithContentsOfFile:imagePath];
//[myImageObj drawAtPoint:CGPointMake(0, 0)];
[myImageObj drawInRect:CGRectMake(0, 0, 320, 480)];
NSString *s = @"我的小狗";
[s drawAtPoint:CGPointMake(100, 0) withFont:[UIFont systemFontOfSize:34.0]];
*/
/*
NSString *path = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"];
UIImage *img = [UIImage imageWithContentsOfFile:path];
CGImageRef image = img.CGImage;
CGContextSaveGState(context);
CGRect touchRect = CGRectMake(0, 0, img.size.width, img.size.height);
CGContextDrawImage(context, touchRect, image);
CGContextRestoreGState(context);
*/
/*NSString *path = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"];
UIImage *img = [UIImage imageWithContentsOfFile:path];
CGImageRef image = img.CGImage;
CGContextSaveGState(context);
CGContextRotateCTM(context, M_PI);
CGContextTranslateCTM(context, -img.size.width, -img.size.height);
CGRect touchRect = CGRectMake(0, 0, img.size.width, img.size.height);
CGContextDrawImage(context, touchRect, image);
CGContextRestoreGState(context);*/
/*
NSString *path = [[NSBundle mainBundle] pathForResource:@"dog" ofType:@"png"];
UIImage *img = [UIImage imageWithContentsOfFile:path];
CGImageRef image = img.CGImage;
CGContextSaveGState(context);
CGAffineTransform myAffine = CGAffineTransformMakeRotation(M_PI);
myAffine = CGAffineTransformTranslate(myAffine, -img.size.width, -img.size.height);
CGContextConcatCTM(context, myAffine);
CGContextRotateCTM(context, M_PI);
CGContextTranslateCTM(context, -img.size.width, -img.size.height);
CGRect touchRect = CGRectMake(0, 0, img.size.width, img.size.height);
CGContextDrawImage(context, touchRect, image);
CGContextRestoreGState(context);
*/
}
判斷UITableView滾動(dòng)是否到底
- (void)scrollViewDidScroll:(UIScrollView*)aScrollView { CGPointoffset = aScrollView.contentOffset;
CGRectbounds = aScrollView.bounds;
CGSizesize = aScrollView.contentSize;
UIEdgeInsetsinset = aScrollView.contentInset;
floaty = offset.y+ bounds.size.height- inset.bottom;
floath = size.height;
floatreload_distance = -20;
if(y > h + reload_distance) {
//距離到底20像 素
}
}
自定義了leftBarbuttonItem左滑返回手勢(shì)失效
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
initWithImage:img
style:UIBarButtonItemStylePlain
target:self
action:@selector(onBack:)];
self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
判斷NSArray倒序
NSArray *tmparr = [[upLoadImageArr reverseObjectEnumerator] allObjects];