zoukankan      html  css  js  c++  java
  • ios 各种技术

    1.NSlog  发布后不打印

    #ifdef DEBUG// 如果有DEBUG这个宏就编译下面一句代码

    #define DDLog(...) NSLog(__VA_ARGS__)

    #else // 如果没有DEBUG这个宏就编译下面一句代码

    #define DDLog(...)

    #endif

    2.三方库及其他整理

    用过的三方库:

    1.​AFNetworking   HTTP 网络请求库  

    2.​SDWebImage 图片缓存

    3.​MBProgressHUD 加载中展示

    4.MMDrawerController​ 抽屉视图(自己也可以模仿再重写)​

    5.​FMDB  sqlite

    6.MJRefresh​   tableview 下拉刷新上拉加载

    7.WebViewJavascriptBridge​ 实现OC与JS交互

    8.SBJSON​   json解析

    9.MJExtension​    模型转换

    10.SVPullToRefresh​  scrollview 上加下拉刷新

    11.​Masonry/SnapKit     自适应布局 (类安卓的相对布局,由于本人1年安卓2年iOS 用起来挺顺手)

    12.​AFPopupView  实现炫酷的跳转

    13.​AwesomeMenu 实现炫酷工具栏效果

    14.MJPhotoBrowser​   实现图片浏览效果,有个导致crash的bug,之后会更

    15.  ZXingObjC   二维码 

    16.MKNetworkKit​ 轻量级HTTP 网络请求库

    17.jpush   推送

    18.alipay  支付宝支付

    19.微信支付

    20.友盟  分享、三方登陆、推送、数据记录、crash记录

    21.iCarousel​  实现Coverflow效果。

    22.SDCycleScrollView  无限轮播器

    没有过的:

    1.JSPatch js脚本更新线上代码(应急用)

    2.CocoaPod​ 三方库的管理工具

    3.更新Xcode后,三方插件不能用的解决方法

    1.在终端中输入  defaults read /Applications/Xcode.app/Contents/Info DVTPlugInCompatibilityUUID 会得到一串码即本版本xocde的UUID,复制留用。

    2.前往文件夹~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/  

     这个插件目录是所谓的插件目录,找到相应的插件,右击显示报内容,打开里面的info.plist,找到DVTPlugInCompatibilityUUIDs 字段,将操作 1 中得到的UUID 添加到此处即可。重启xcode就可以使用了

    4.获取带毫秒的NSDate

    NSDateFormatter *dateFormatter = [[NSDateFormatteralloc] init];

        [dateFormatter setDateStyle:NSDateFormatterMediumStyle];

        [dateFormatter setTimeStyle:NSDateFormatterShortStyle];

        //[dateFormatter setDateFormat:@"hh:mm:ss"]

        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS"];

        NSLog(@"-------0Date%@", [dateFormatter stringFromDate:[NSDate date]]);

    5.WebViewJavascriptBridge的使用

    转载2015-07-07 16:21:25

    1.初始化一个webview(viewdidload)


    @property (nonatomic, strong) WebViewJavascriptBridge *mainbridge;

    UIWebView* webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:webView];
     2.将此webview与WebViewJavascriptBridge关联(viewdidload)

        [WebViewJavascriptBridgeenableLogging];
    self.mainbridge = [WebViewJavascriptBridgebridgeForWebView:weakSelf webViewDelegate:(WVJB_WEBVIEW_DELEGATE_TYPE*)weakSelf.delegatehandler:^(id data, WVJBResponseCallback responseCallback) {
    根据data 就可以判断了​
          }
     (3)oc给js传值(通过 response接受返回值 )  
    [mainbridge send:@"A string sent from ObjC before Webview has loaded."responseCallback:^(id responseData) {
            NSLog(@"objc got response! %@", responseData);
        }];

    6.swift 中AnyObject 转string 转 array

    从json数组取得AnyObject  类型的anyData

              var anyData: AnyObject! = resultDic.objectForKey("wxts1")

    转string  

               var Datatext: String! = String(stringInterpolationSegment: anyData)           

    转array

    1.        let DataArray: AnyObject! = anyData​

     2.           var DataArray:NSArray = (anyData as! NSArray) asArray​

    7.在swift中使用oc库

    只要用到的是个.h  文件   

    1.先创建一个.h文件,可命名为Bridging-Header.​h

    2.​在build setting 中找到Object-C Bridging Header 中添加Bridging-Header.​h 的相对路径

    3.在​Bridging-Header.​h 中引入锁需的三方库或者oc类   如:#import"AFNetworking.h"

    8.NSString 打印为(null),为空判断

    NSString* remain_delivery_day = [resultDic objectForKey:@"remain_delivery_day"]

    服务器返回为空的话​​remain_delivery_day便会输出(null),

    发现​​remain_delivery_day isKindOfClass:[NSNull class]、[remain_delivery_day isEqualToString:@"(null)"] 都不可判断其为空,==nil也不行

    解决方案最常用的是​remain_delivery_day length]==0

    还有[remain_delivery_day isEqual:[NSNullnull]] ​

    其实明白:​nil是一个对象指针为空,Nil是一个类指针为空,NULL是基本数据类型为空。区别就是nil是一个对象,而NULL只是一个值   看这个问题就不是那么难了

    9.放大一个imageview

    #define CONST_animation_time 0.5

    #define CONST_enlarge_proportion 15.0

        

        CGPoint UpPointOfView(UIView *view)

        {

            return (CGPoint){view.center.x, 200+2+55/2};

        };

        

        - (void) circleAnimate:(UIImageView*)view

        {

            CGContextRef context = UIGraphicsGetCurrentContext();

            [UIView beginAnimations:nil context:context];

            [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

            [UIView setAnimationDuration:CONST_animation_time];

            [view setCenter:UpPointOfView(view)];

            

            CABasicAnimation *scalingAnimation = (CABasicAnimation *)[view.layer animationForKey:@"scaling"];

            

            if (!scalingAnimation)

            {

                scalingAnimation = [CABasicAnimation animationWithKeyPath:@"transform"];

                scalingAnimation.repeatCount=1;

                scalingAnimation.duration=CONST_animation_time;

                scalingAnimation.autoreverses=NO;

                scalingAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];

                scalingAnimation.fromValue=[NSValue valueWithCATransform3D:CATransform3DMakeScale(1.0, 1.0, 1.0)];

                scalingAnimation.toValue=[NSValue valueWithCATransform3D:CATransform3DMakeScale(CONST_enlarge_proportion,CONST_enlarge_proportion, 1.0)];

            }

            

            [view.layer addAnimation:scalingAnimation forKey:@"scaling"];

            view.layer.transform = CATransform3DMakeScale(CONST_enlarge_proportion,CONST_enlarge_proportion, 1.0);

            [UIView commitAnimations];

        }

    10.利用手势给图片添加点击事件

    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(imageviewclick)];

        [imageview addGestureRecognizer:singleTap];//点击图片事件,

    imageview.userInteractionEnabled = YES;

    11.iOS伪表单上传图片

    - (void) imageUpload:(UIImage *) image{

        //把图片转换成imageDate格式

        NSData *imageData = UIImageJPEGRepresentation(image, 0.5);

        //传送路径

        NSString *urlString = @"http://www.呃呃呃呃呃.com/ImageUpload/uploadImg";

        //建立请求对象

        NSMutableURLRequest * request = [[NSMutableURLRequestalloc] init];

        //设置请求路径

        [request setURL:[NSURLURLWithString:urlString]];

        //请求方式

        [request setHTTPMethod:@"POST"];

        //一连串上传头标签

        NSString *boundary = (NSString*)@"---------------------------14737809831466499882746641449";

        NSString *contentType = [NSStringstringWithFormat:@"multipart/form-data; boundary=%@",boundary];

        [request addValue:contentType forHTTPHeaderField: @"Content-Type"];

        NSMutableData *body = [NSMutableDatadata];

        [body appendData:[[NSStringstringWithFormat:@" --%@ ",boundary]dataUsingEncoding:NSUTF8StringEncoding]];

        [body appendData:[@"Content-Disposition: form-data; name="upfile"; filename="bb" "dataUsingEncoding:NSUTF8StringEncoding]];

        [body appendData:[@"Content-Type: application/octet-stream "dataUsingEncoding:NSUTF8StringEncoding]];

        [body appendData:[NSDatadataWithData:imageData]];

        [body appendData:[[NSStringstringWithFormat:@" --%@-- ",boundary]dataUsingEncoding:NSUTF8StringEncoding]];

        [request setHTTPBody:body];

        //上传文件开始

        //+ (NSData *)sendSynchronousRequest:(NSURLRequest *)request returningResponse:(NSURLResponse **)response error:(NSError **)error;

        

        NSData *returnData = [NSURLConnectionsendSynchronousRequest:requestreturningResponse:nilerror:nil];

        //获得返回值

        NSString *returnString = [[NSStringalloc] initWithData:returnDataencoding:NSUTF8StringEncoding];

        NSData *data = [returnString dataUsingEncoding:NSUTF8StringEncoding];

        NSDictionary *resultDic = [NSJSONSerializationJSONObjectWithData:dataoptions:NSJSONReadingMutableLeaveserror:nil];

    //    NSLog(@"%@",resultDic);

        NSString * str11 = [NSStringstringWithFormat:@",%@",[resultDicobjectForKey:@"img_url"]];

        [urlImageHeadappendString:str11];

    }

    12.iOS简单post

    NSString *postString = [NSStringstringWithFormat:@"         {\"userName\":\"%@\",\"userPass\":\"%@\",\"version\":\"1.0\"}",self.userField.text,self.passwordField.text];

        NSLog(@"%@",postString);

        //一般转化称UTF-8,这里服务器需要ASCII

        NSData* postData = [postStringdataUsingEncoding:NSASCIIStringEncodingallowLossyConversion:YES];

        NSMutableURLRequest *request = [[[NSMutableURLRequestalloc] init] autorelease];

        [requestsetURL:[NSURLURLWithString:@"http://lib.wap.zol.com.cn/test/login.php"]];

        [requestsetCachePolicy:NSURLRequestUseProtocolCachePolicy];

        [requestsetTimeoutInterval:100.0];

        [request setHTTPMethod:@"POST"];

        [request setHTTPBody:postData];

        // 应该是application/x-www-form-urlencoded,但对方服务器写成了appliction/x-www-form-urlencoded,告诉服务器是一个表单提交数据方式

        [requestsetValue:@"appliction/x-www-form-urlencoded"forHTTPHeaderField:@"Content-Type"];

        //得到提交数据的长度

        NSString* len = [NSString stringWithFormat:@"%d", [postData length]];

        //添加一个http包头告诉服务器数据长度是多少

        [requestsetValue:len forHTTPHeaderField:@"Content-Length"];

        [NSURLConnectionconnectionWithRequest:request delegate:self];

    13.iOS原生json解析

    NSData *jsonData = [[NSData alloc] initWithContentsOfFile:JSON_PATH];

        NSError *error = nil;

        id jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:&error;];

        

        if (jsonObject != nil && error == nil){

            NSLog(@"Successfully deserialized...");

            if ([jsonObject isKindOfClass:[NSDictionary class]]){

                NSDictionary *deserializedDictionary = (NSDictionary *)jsonObject;

                NSLog(@"Dersialized JSON Dictionary = %@", deserializedDictionary);

            } elseif ([jsonObject isKindOfClass:[NSArray class]]){

                NSArray *deserializedArray = (NSArray *)jsonObject;

                NSLog(@"Dersialized JSON Array = %@", deserializedArray);

            } else {

                NSLog(@"An error happened while deserializing the JSON data.");

            }

        }

    14.模仿MBProgressHUD 成功

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil

                                                    message:[@"Alert"

                                                             delegate:nil

                                                             cancelButtonTitle:nil//NSLocalizedString(@"OK", @"OK")   //

                                                             otherButtonTitles:nil];

                          //[alert setBounds:CGRectMake(alert.bounds.origin.x, alert.bounds.origin.y, alert.bounds.size.width, alert.bounds.size.height+30.0)];

                          [alert show];

                          

                          UIActivityIndicatorView *indicator = [[UIActivityIndicatorViewalloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];

                          

                          // Adjust the indicator so it is up a few pixels from the bottom of the alert

                          indicator.center = CGPointMake(alert.bounds.size.width/2,  alert.bounds.size.height-40.0);

                          [indicator startAnimating];

                          [alert insertSubview:indicator atIndex:0];

        [indicator release];

                          

       [NSTimer scheduledTimerWithTimeInterval:3.0f

                                                           target:self

                                                         selector:@selector(dismissAlert:)

                                                         userInfo:[NSDictionary dictionaryWithObjectsAndKeys:alert, @"alert", @"testing ", @"key" ,nil]  //nil.

                                                          repeats:NO];

                          

                          NSLog(@"release alert");

                          [alert release];

                          

                          -(void) dismissAlert:(NSTimer *)timer{

      NSLog(@"release timer");

      NSLog([[timer userInfo] objectForKey:@"key"]);

      UIAlertView* alert = [[timer userInfo] objectForKey:@"alert"];

      [alert dismissWithClickeonIndex:0 animated:YES];

                              

                          }

                          

                          //

                          [timer invalidate];

                          timer = nil;

    15.UITableView   滑动到某一行

    创建NSIndexPath

      NSIndexPath*scrollIndexPath =[NSIndexPath indexPathForRow:10 inSection:0];

    自己的tableview开始滚动​

    ​[[self tableView] scrollToRowAtIndexPath:scrollIndexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];

    16.常用小代码

    [[[UIApplication sharedApplication] keyWindow] endEditing:YES];//关闭键盘

    取消cell的选中状态cell.selectionStyle = UITableViewCellSelectionStyleNone;

    状态栏          [[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleDefault];

        self.navigationController.navigationBarHidden = yes;​隐藏引导栏

    17.关于Unbalanced calls to begin/end appearance transitions for 

    在自定义的tabbarvc里添加

    - (void)viewWillAppear:(BOOL)animated

    {

       

        [self.selectedViewController beginAppearanceTransition: YES animated: animated];

    }

    -(void) viewDidAppear:(BOOL)animated

    {

        [self.selectedViewController endAppearanceTransition];

    }

    -(void) viewWillDisappear:(BOOL)animated

    {

        [self.selectedViewController beginAppearanceTransition: NO animated: animated];

    }

    -(void) viewDidDisappear:(BOOL)animated

    {

        [self.selectedViewController endAppearanceTransition];

    }

    18.CUICatalog: Invalid asset name supplied: (null)

    [UIImage imageNamed:name];但是这个name却是空的,所以就报了这个错了。

    解决方法,在项目中搜索[UIImage imageNamed:,然后打印看看所谓的name是否为空。找到后替换


  • 相关阅读:
    Java学习日记Ⅰ
    docker 安装redis
    maven 打包 把第三方包也打进去
    wiki 配置数据源 编码要是utf8 不能是utf8mb4
    SCFT用公钥登录
    配置tomcat重启脚本
    tomcat
    centos7 搭建rabbitmq服务 3.7.15
    安装openoffice
    tomcat 日期切分
  • 原文地址:https://www.cnblogs.com/pp-pping/p/4651610.html
Copyright © 2011-2022 走看看