美文网首页
ios 开发总结(一)

ios 开发总结(一)

作者: ducks | 来源:发表于2016-07-24 03:38 被阅读50次

    开发知识汇总

    关键字const的位置

    const意味着”只读”,分析下面的含义

    const int a;
    int const a;
    // 前两个的作用是一样,a是一个常整型数。
    const int *a;
    // 第三个意味着a是一个指向常整型数的指针(整型数是不可修改的,但指针可以)
    int * const a;
    // 第四个意思a是一个指向整型数的常指针(指针指向的整型数是可以修改的,但指针是不可修改的)
    int const * const a;
    // a是一个指向常整型数的常指针(指针指向的整型数是不可修改的,同时指针也是不可修改的)。表示a是一个指针常量,初始化的时候必须固定指向一个int常量或者int变量,之后就不能再指向别的地方了,它总是把它所指向的目标当作一个int常量。也可以写成const int* const a;含义相同。
    
    滑动隐藏导航栏(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;
    
    仿系统弹出出动画(渐变大)

    必须把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];
    }
    
    关于View
    view.layer.shouldRasterize = YES;//去除View锯齿
    view.layer.shadowColor //投影颜色
    view.layer.shadowOffset //投影偏移量
    view.layer.shadowRadius //投影弧度
    view.layer.shadowPath //投影路径
    #设置View 的圆角等样式都是设置 view.layer 的属性
    
    关于导航栏
    //设置导航栏颜色(全局设置)
    [[UINavigationBar appearance] setBarTintColor:UIColorFromRGB(0x067AB5)];
    //设置导航栏背景图片
    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav_bg.png"] forBarMetrics:UIBarMetricsDefault]; 
    //自定义返回按钮图片(默认状态)
    [[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:@"back_btn.png"]];
    //自定义返回按钮图片(按下状态)
    [[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"back_btn.png"]]; 
    #设置导航返回按钮颜色(除了返回按钮,tintColor属性会影响到所有按钮标题和图片。)
    [[UINavigationBar appearance] setTintColor:[UIColor whiteColor]]; 
    //修改导航栏的返回按钮颜色
    self.navigationController.tintcolor = color
    //设置导航栏标题的风格(dictionary    key 
        UITextAttributeFont – 字体key
        UITextAttributeTextColor – 文字颜色key
        UITextAttributeTextShadowColor – 文字阴影色key
        UITextAttributeTextShadowOffset – 文字阴影偏移量key)
        UITextAttributeFont 字体大小
    [[UINavigationBar appearance] setTitleTextAttributes:(NSDictionary<NSString *,id> * _Nullable)]
    //自定义导航栏View (一般用于设置图片,或者按钮)
    self.navigationItem.titleView = view
    
    版本号比较
     if ([string1 compare:@"string2"] == 0) {
      //版本相等        
      }
    
    
    禁止键盘弹出时UIWebView自动滑动
    webview.scrollView.delegate=self;
     -(UIView*)viewForZoomingInScrollView:(UIScrollView*)scrollView {
       return nil;
     }
    
    有时候layer.cornerRadius并不能满足需求,自己实现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的填充区域中,alpha值不为零的部分,self会被绘制;alpha值为零的部分,self不会被绘制,甚至不会响应touch
     }
    
    drawrect 画线
    - (void)drawRect:(CGRect)rect  
    {  
        CGContextRef context = UIGraphicsGetCurrentContext();  
           
       
           
        /*NO.1画一条线 
           
         CGContextSetRGBStrokeColor(context, 0.5, 0.5, 0.5, 0.5);//线条颜色 
         CGContextMoveToPoint(context, 20, 20); 
         CGContextAddLineToPoint(context, 200,20); 
         CGContextStrokePath(context); 
        */  
       
           
           
        /*NO.2写文字 
           
        CGContextSetLineWidth(context, 1.0); 
        CGContextSetRGBFillColor (context, 0.5, 0.5, 0.5, 0.5); 
        UIFont  *font = [UIFont boldSystemFontOfSize:18.0]; 
        [@"公司:北京中软科技股份有限公司\n部门:ERP事业部\n姓名:McLiang" drawInRect:CGRectMake(20, 40, 280, 300) withFont:font]; 
        */  
       
           
        /*NO.3画一个正方形图形 没有边框 
      
        CGContextSetRGBFillColor(context, 0, 0.25, 0, 0.5); 
        CGContextFillRect(context, CGRectMake(2, 2, 270, 270)); 
        CGContextStrokePath(context); 
        */  
        
           
        /*NO.4画正方形边框 
          
        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画方形背景颜色 
           
        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四条线画一个正方形 
        //画线 
            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); //开始画线 
         */  
           
           
           
        /*  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 
         画一个实心的圆 
       
         CGContextFillEllipseInRect(context, CGRectMake(95, 95, 100.0, 100)); 
        */  
           
           
           
        /*NO.12 
         画一个菱形 
        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 画矩形 
        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); 
        */  
           
        /*填充一个蓝色边的红色矩形 
        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); 
        */  
           
        /*画弧 
         //弧线的是通过指定两个切点,还有角度,调用CGContextAddArcToPoint()绘制 
        CGContextSetLineWidth(context, 2.0); 
        CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor); 
        CGContextMoveToPoint(context, 100, 100); 
        CGContextAddArcToPoint(context, 100,200, 300,200, 100); 
        CGContextStrokePath(context); 
        */  
          
           
        /* 
        绘制贝兹曲线 
        //贝兹曲线是通过移动一个起始点,然后通过两个控制点,还有一个中止点,调用CGContextAddCurveToPoint() 函数绘制 
        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);//跳过3个再画虚线,所以刚开始有6-(3-2)=5个虚点 
          
        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滚动是否到底

    - (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左滑返回手势失效
    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];
     
    

    相关文章

      网友评论

          本文标题:ios 开发总结(一)

          本文链接:https://www.haomeiwen.com/subject/nriwjttx.html