zoukankan      html  css  js  c++  java
  • 细节关注(持续更新。。。)

    1、屏幕是配问题

      ios7之后包含7状态栏(20点,44像素)、导航栏(44点,88像素)、标签栏(49点,98像素),各种“栏”变的透明了,比如一张background640*920.png(状态栏高度为20点,对应像素为40点,所以为920的高)的图片能运行在ios6的系统上,但在7和7之后的系统中运行会被拉伸,因为7和7之后的系统需要background640*960.png的图片。显然这不是我们想要的。那么如何解决呢?让美工做一张640*960的图片,在程序中进行版本判断。

    if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
        _imageView.image = [UIImage imageNamed:@"background640x960.png"]; 
     }
    

      判断操作系统版本的还有[[UIDevice currentDevice] systemVersion] 语句,通过该语句我们可以获得一个字符串,如果是iOS 6.1则返回6.1。通过判断这个字符串也可以判断iOS系统的版本号。

    2、状态栏的隐藏

      在IOS6的系统下,隐藏状态栏为:

    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    

      这个应用如果在iOS 7下面运行,你会发现状态栏没有隐藏。在iOS 7下要想实现状态栏的隐藏还需要在工程里做一下设置。

      首先要设置Xcode工程属性,这个属性是在HelloWorld-Info.plist中设置的, HelloWorld-Info.plist是按照<xxx工程名 >-Info.plist命名的,其中的HelloWorld是我们当前的Xcode工程的名。我们需要打开HelloWorld -Info.plist文件,右键弹出菜单,选择Add Row菜单项,在属性列表文件中添加一行。然后在添加的行中选择View controller-based status bar appearance属性,选择好这个属性后,再在后面的Value中选择NO。这样这个前期的设置工作就完成了。

      如果需要显示状态栏和设置状态栏的风格,进行如下操作:

    //设置状态栏风格
     [[UIApplication sharedApplication] setStatusBarHidden:NO];
     [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];//默认黑色
     [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleLightContent];//设置为白色
    

      

    3、设置非ARC

      大部分的第三方库文件都是MRC的,怎样进行转变呢?

      选 择TARGETS→MyNotes(你自己的Target)→Build Phases→Compile Sources,选择源文件,敲击回车键弹出对话框,在对话框中输入“-fno-objc-arc”。

    4、本地通知

    NSDate *date = [NSDate dateWithTimeIntervalSinceNow:10];//10秒
    UILocalNotification *note = [[UILocalNotification alloc]init];
    note.alertBody = @"win";
    note.fireDate = date;
    [[UIApplication sharedApplication] scheduleLocalNotification:note];

     5、调试信息

    发布的时候会屏蔽调试信息

    building settings->Preprocessor Mecros->Debug

    添加宏定义VIEW_DEBUG

    在pch包含的头文件中

    #pragma mark - 日志开关
    #ifdef VIEW_DEBUG
    #define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
    #else
    #define DLog(...)
    #endif

     6、链接去评价

    UIApplication * application = [UIApplication sharedApplication];
    [application openURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://itunes.apple.com/cn/app/id%@",xw_appid]]];

     7、将general->identify->team设为None

    a.修改***.xcodeproj/project.pbxproj文件

    b.删除TargetAttribtes一段,保存,即可

    8、标签触碰时调用touchesBegin:withEvent方法时需要注意:

    a、view设置背景颜色

    b、开启view中的userInteractionEnabled属性为YES

    9、检测震动

    motionBegin:withEvent

    motionEnded:withEvent

    motionCancelled:withEvent

    需要注意:

    a、创建UIView子类,重写canBecomeFirstResponder:方法返回YES

    b、将子类addSubView:追加到界面上

    c、触摸对象必须指定为第一响应者 [子类 becomeFirstResponder]

    10、对数据进行加密,使用MD5

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    #import <CommonCrypto/CommonDigest.h>
    - (NSString *)md5:(NSString *)str
    {
        const char *cStr = [str UTF8String];
        unsigned char result[16];
        CC_MD5(cStr, strlen(cStr), result); // This is the md5 call
        return [NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
            result[0], result[1], result[2], result[3], 
            result[4], result[5], result[6], result[7],
            result[8], result[9], result[10], result[11],
            result[12], result[13], result[14], result[15]
            ]; <br><br>  //NSMutableString *hash = [NSMutableString string];  <br>  //for (int i = 0; i < 16; i++)   <br>  //  [hash appendFormat:@"%02X", result[i]];   <br>  //return [hash lowercaseString]; <br><br>}

    11、layoutSubviews在以下情况下会被调用:

    1、init初始化不会触发layoutSubviews
    2、addSubview会触发layoutSubviews
    3、设置view的Frame会触发layoutSubviews,当然前提是frame的值设置前后发生了变化
    4、滚动一个UIScrollView会触发layoutSubviews
    5、旋转Screen会触发父UIView上的layoutSubviews事件
    6、改变一个UIView大小的时候也会触发父UIView上的layoutSubviews事件

    12、drawRect:在什么时候调用

    This method is called when a view is first displayed or when an event occurs that invalidates a visible part of the view. You should never call this method directly yourself. To invalidate part of your view, and thus cause that portion to be redrawn, call the setNeedsDisplay or setNeedsDisplayInRect: method instead.

    13、如何使用已废弃的API且不报警告

    或者

      

    14. 个人账户和企业帐户的区别加入开发者计划(花钱)

    个人/公司:99美元
    共同点:只能发布APPStore
    个人和公司的区别:
    1.个人只能添加一个iOS Development
    2.公司可以添加无数个iOS Development
    3.个人证书申请简单
    4.公司证书申请麻烦,需要邓氏编码,相当于公司的身份证
    缺点:上传AppStore需要审核,至少一周
     
    企业证书:299美元
    不能发布APPStore,给特定的人群用,比如医疗应用,政府应用
    通过链接下载应用安装
    缺点:安装设备有限制,申请也麻烦,需要邓式编码
    真机调试捷径:淘宝买真机账号。
     
    15.真机调试的主要步骤
    1.登录开发者主页
    2.生成cer证书:cer是一个跟电脑相关联的证书文件,让电脑具备真机调试的功能
    3.添加App ID:调试哪些app?
    4.注册真机设备:哪台设备需要做真机调试?
    5.生成MobileProvision文件:结合2、3、4生成一个手机规定文件
    6.导入cer、MobileProvision文件
     
    最终会得到2个文件
    Cer文件:让电脑具备真机调试的功能
    MobileProvision文件:哪台设备、哪些app、哪台电脑需要做真机调试?
     
    16. 打印tableView的整个contentSize中的内容,包括显示在屏幕上和未加载出来的视图
    UIGraphicsBeginImageContext(self.mainTableView.contentSize);
    [self.mainTableView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    UIPrintInteractionController *printer = [UIPrintInteractionController sharedPrintController];
    printer.printingItem = viewImage;
    UIPrintInfo *info = [UIPrintInfo printInfo];
    printer.printInfo = info;
    UIPrintInteractionCompletionHandler completionHandler =
    ^(UIPrintInteractionController *pic, BOOL completed, NSError *error) {
        if (!completed && error)
            NSLog(@"FAILED! due to error in domain %@ with error code %u: %@",
                  error.domain, error.code, [error localizedDescription]);
    }; 
    UIButton * printButton = (UIButton *)sender;
    if(UIUserInterfaceIdiomPad == [[UIDevice currentDevice] userInterfaceIdiom]){
        [printer presentFromRect:printButton.frame inView:self.view animated:YES completionHandler:completionHandler];
    } else {
        [printer presentAnimated:YES completionHandler:completionHandler];
    }

    17 .打印pdf。将PDF作为输入传给打印机进行打印

    - (void)createPDFfromUIView:(UIView*)aView saveToDocumentsWithFileName:(NSString*)aFilename
    {
        NSMutableData *pdfData = [NSMutableData data];
        UIGraphicsBeginPDFContextToData(pdfData, aView.bounds, nil);
        UIGraphicsBeginPDFPage();
        CGContextRef pdfContext = UIGraphicsGetCurrentContext();
        [aView.layer renderInContext:pdfContext];
        UIGraphicsEndPDFContext();
           NSArray* documentDirectories = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask,YES);
    
        NSString* documentDirectory = [documentDirectories objectAtIndex:0];
        NSString* documentDirectoryFilename = [documentDirectory stringByAppendingPathComponent:aFilename];
        [pdfData writeToFile:documentDirectoryFilename atomically:YES];
        NSLog(@"documentDirectoryFileName: %@",documentDirectoryFilename);
    }
    
    -(void)getPDF{
         NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); 
         NSString *documentsPath = [paths objectAtIndex:0]; 
         NSString *filePath = [documentsPath stringByAppendingPathComponent:@"myPdf"];
         NSLog(@"filePath: %@",filePath);
    
         NSData *pngData = [NSData dataWithContentsOfFile:filePath];
        [displayPDFView loadData:pngData MIMEType:@"application/pdf" textEncodingName:@"utf-8" baseURL:nil];
        [self.view setBackgroundColor:[UIColor colorWithWhite:0.5 alpha:0.0]];
        displayPDFView.hidden = NO;
    
    }
    打印机代码
    NSString *path = [[NSBundle mainBundle] pathForResource:@"demo" ofType:@"png"];
        NSData *dataFromPath = [NSData dataWithContentsOfFile:path];
    
        UIPrintInteractionController *printController = [UIPrintInteractionController sharedPrintController];
    
        if(printController && [UIPrintInteractionController canPrintData:dataFromPath]) {
    
            printController.delegate = self;
    
            UIPrintInfo *printInfo = [UIPrintInfo printInfo];
            printInfo.outputType = UIPrintInfoOutputGeneral;
            printInfo.jobName = [path lastPathComponent];
            printInfo.duplex = UIPrintInfoDuplexLongEdge;
            printController.printInfo = printInfo;
            printController.showsPageRange = YES;
            printController.printingItem = dataFromPath;
    
            void (^completionHandler)(UIPrintInteractionController *, BOOL, NSError *) = ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
                if (!completed && error) {
                    NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code);
                }
            };
    
            [printController presentFromRect:btnPrint.frame inView:btnPrint.superview
                                    animated:YES completionHandler:completionHandler];
        } 
    解决方法 1:
    您可以通过此代码打印 pdf......
     #if (READER_ENABLE_PRINT == TRUE) // Option
    
    Class printInteractionController = NSClassFromString(@"UIPrintInteractionController");
    
    if ((printInteractionController != nil) && [printInteractionController isPrintingAvailable])
    {
        NSURL *fileURL = document.fileURL; // Document file URL
    
        printInteraction = [printInteractionController sharedPrintController];
    
        if ([printInteractionController canPrintURL:fileURL] == YES)
        {
            UIPrintInfo *printInfo = [NSClassFromString(@"UIPrintInfo") printInfo];
    
            printInfo.duplex = UIPrintInfoDuplexLongEdge;
            printInfo.outputType = UIPrintInfoOutputGeneral;
            printInfo.jobName = document.fileName;
    
            printInteraction.printInfo = printInfo;
            printInteraction.printingItem = fileURL;
            printInteraction.showsPageRange = YES;
    
            [printInteraction presentFromRect:button.bounds inView:button animated:YES completionHandler:
                ^(UIPrintInteractionController *pic, BOOL completed, NSError *error)
                {
                    #ifdef DEBUG
                        if ((completed == NO) && (error != nil)) NSLog(@"%s %@", __FUNCTION__, error);
                    #endif
                }
            ];
        }
    }
    
      #endif //
  • 相关阅读:
    PB调用.NET类库详解
    一个游标的性能问题
    WCF实例与并发的一些测试
    PB调用.NET代码的两个入口函数
    SQL数据库表防JS木马注入
    Atitit 收入理论大总结 4位一体 4象限理论 财政收入理论 6位一体
    Atitit 融资 之道 圈钱之道 attilax总结
    Atitit 组织架构的如何划分 划分方法attilax大总结
    Atitit 每个人都应该实施的互联网金融战略 attilax总结
    Atitit 研发组织与个人如何gdp计算法 attilax总结
  • 原文地址:https://www.cnblogs.com/yyzanll/p/4305086.html
Copyright © 2011-2022 走看看