• 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);

  • 相关阅读:
    python list介绍
    python unittest模块
    python 贪婪算法
    python 动态规划:背包问题
    汇编语言 基础知识(王爽)
    python 迪克斯特拉(Dijkstra)
    python 广度优先查找 (最短路径)
    Python 快速排序
    python 分而治之 找零数量 最小组合
    移动端的头部标签和 meta
  • 原文地址:https://www.cnblogs.com/Cristen/p/2849557.html
Copyright © 2020-2023  润新知