zoukankan      html  css  js  c++  java
  • iphone开发笔记和技巧总结各处收集所得

    iphone开发笔记和技巧总结

    1.iphone程序中实现截屏的一种方法

    在iphone程序中实现截屏的一种方法:
    //导入头文件
    #import QuartzCore/QuartzCore.h
    //将整个self.view大小的图层形式创建一张图片image UIGraphicsBeginImageContext(self.view.bounds.size);
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage*image=UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    //然后将该图片保存到照片库
    UIImageWriteToSavedPhotosAlbum(image,self,nil,nil);

    2.Objective-C 画图

    1.颜色和字体

         UIKit提供了UIColor和UIFont类来进行设置颜色和字体,

         UIColor *redColor=【UIColor redColor】;

        【redColor set】;//设置为红色

         UIFont *front=【UIFont systemFontOfSize:14.0】;//获得系统字体

        【myLable setFont:font】;//设置文本对象的字体

     2.drawRect方法
         对于画图,你首先需要重载drawRect方法,然后调用setNeedsDisplay方法让系统画图:
         -(void)drawRect:(CGRect)rect;//在rect指定的区域画图

         -(void)setNeedsDisplay;//让系统调用drawRect画图

      3.CoreGraphics API

         UiKit所提供的画图类比较简单,就是我们上面所说的UIRectFill和UIRectFrame两个方法。对于复杂的画图。你需要   使用CoreGraphics API.

       步骤一:获得当前画图的上下文(CGContextRef) UIGraphicsGetCurrentContext(void);

       步骤二:定义一个图的轨迹(path),比如你要画一个三角形,那么,第一步就是画出这个三角形的轮廓。但是并不在屏幕上显示该图。

       步骤三:设置填充颜色

       步骤四: 设置图框颜色

       步骤五:让系统画图,这是你就看到了所化的图形 

    3.延时函数和Timer的使用
    延时函数:
    [NSThread sleepForTimeInterval:5.0]; //暂停5s.

    Timer的使用:
    NSTimer *connectionTimer;  //timer对象

    //实例化timer
    self.connectionTimer=[NSTimerscheduledTimerWithTimeInterval:1.5 target:selfselector:@selector(timerFired:) userInfo:nil repeats:NO];
    [[NSRunLoop currentRunLoop]addTimer:self.connectionTimer forMode:NSDefaultRunLoopMode];
    //用timer作为延时的一种方法   
    do{
    [[NSRunLoop currentRunLoop]runUntilDate:[NSDatedateWithTimeIntervalSinceNow:1.0]];
    }while(!done); 

    //timer调用函数
    -(void)timerFired:(NSTimer *)timer{
    done =YES;
    }

    4.启动界面的制作
    iPhone开发实现splash画面非常简单,做一个全屏的欢迎页的图片,把它命名为Default.png,然后放在Xcode工程的Resource里面。
    在XXXAppDelegate.m程序中,插入如下代码:
    (BOOL)application:(UIApplication*)application
    didFinishLaunchingWithOp
    tions:(NSDictionary *)launchOptions {
     
     //–inserta delay of 5 seconds before the splash screendisappears–
     
     [NSThread sleepForTimeInterval:5.0];
     
     //Override point for customization after applicationlaunch.
     
     //Add the view controller’s view to the window anddisplay.
     
     [windowaddSubview:viewController.view];
     
     [windowmakeKeyAndVisible];
     
     return YES;
    }

    这样splash页面就停留5秒后,消失了。

    5.截取屏幕图片
    //创建一个基于位图的图形上下文并指定大小为CGSizeMake(200,400)
    UIGraphicsBeginImageContext(CGSizeMake(200,400));

    //renderInContext 呈现接受者及其子范围到指定的上下文

    [self.view.layerrenderInContext:UIGraphicsGetCurrentContext()];
      
     //返回一个基于当前图形上下文的图片
     UIImage *aImage =UIGraphicsGetImageFromCurrentImageContext();
     
     //移除栈顶的基于当前位图的图形上下文
    UIGraphicsEndImageContext();

    //以png格式返回指定图片的数据
    imageData = UIImagePNGRepresentation(aImage);

  • 相关阅读:
    SQL语句之奇形怪状的冷门函数
    计算累计收益
    关于SQL表字段值缺失的处理办法
    虚拟机移植到另一台机器
    分分钟搞懂rank() over(partition by)的使用
    分分钟搞懂union与union all
    【转】10分钟就能学会的.NET Core配置
    【转】依赖注入的威力,.NET Core的魅力:解决MVC视图中的中文被html编码的问题
    【转】Asp.Net Core2.0获取客户IP地址,及解决发布到Ubuntu服务器获取不到正确IP解决办法
    【转】在.net Core 中像以前那样的使用HttpContext.Current
  • 原文地址:https://www.cnblogs.com/Cristen/p/2849557.html
Copyright © 2011-2022 走看看