• 开发细节(一)


    1. iOS6+的UIScrollerView不滚动的问题

    • setContentSize方法需要写到viewDidAppear里,而不是viewDidLoad里了。
    • scrollEnabled需要设置为YES
    • contentSize必须比控件的frame尺寸大
    • 当做一些控件滑动效果时,最好是将pagingEnabled设置为NO,autoresizesSubviews最好也设置为NO。

    2. 弧度与角度的转换

    1角度 = π/180 弧度

    1弧度 = 180/π角度

    360角度 = 360 * π/180 = 2π弧度 = 一整圈

    3. 图片的缩放操作

    UIImage *bigImage = [UIImage imageNamed:@"myPhoto"];
    
    CGSize scaleSize = CGSizeMake(80, 80);
    
    //Creates a bitmap-based graphics context and makes it the current context. (创建一个基于位图的context,并设置成当前正使用的context)
    UIGraphicsBeginImageContext(scaleSize);
    
    //Draws the entire image in the specified rectangle, scaling it as needed to fit. (在指定的区域內绘制整个图形,并缩放以适应该区域)
    [bigImage drawInRect:CGRectMake(0, 0, scaleSize.width, scaleSize.height)];
    
    //Returns an image based on the contents of the current bitmap-based graphics context. (从当前基于位图的context里得到图片)
    UIImage *smallImage = UIGraphicsGetImageFromCurrentImageContext();
    
    //Removes the current bitmap-based graphics context from the top of the stack. (将当前基于位图的context从堆栈移除)
    UIGraphicsEndImageContext();
    
    UIImageView *imageView = [[UIImageView alloc] initWithImage:smallImage];
    [self.view addSubview:imageView];

    4. 画线

    CGSize scaleSize = CGSizeMake(200, 200);
    
    UIGraphicsBeginImageContext(scaleSize);
    
    CGContextRef cgContext = UIGraphicsGetCurrentContext();
    
    //style
    CGContextSetLineCap(cgContext, kCGLineCapRound);
    CGContextSetLineWidth(cgContext, 3.0);
    CGContextSetRGBStrokeColor(cgContext, 1.0, 0.0, 1.0, 1.0);
    
    //line 1
    CGContextBeginPath(cgContext);
    CGContextMoveToPoint(cgContext, 20, 20);
    CGContextAddLineToPoint(cgContext, 100, 100);
    CGContextStrokePath(cgContext);
    
    //line 2
    CGPoint aPoints[3];
    aPoints[0] =CGPointMake(100, 80);
    aPoints[1] =CGPointMake(130, 80);
    aPoints[2] =CGPointMake(60, 140);
    CGContextAddLines(cgContext, aPoints, 3);
    CGContextDrawPath(cgContext, kCGPathStroke);
    
    CGContextFlush(cgContext);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    
    UIGraphicsEndImageContext();
    
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    [self.view addSubview:imageView];

    5. 随机数的生成

    1. 获取一个随机整数范围:0<=rand<100
    arc4random() % 100;
    
    2. 获取一个随机整数范围:100<=rand<500
    (arc4random() % 101) + 400;
    3. 获取一个随机整数,from<=rand<to - (int)getRandomNumber:(int)from to:(int)to { return (int)(from + (arc4random() % (to – from + 1))); //+1,result is [from to]; else is [from, to) //from 100 to 500 //100 + arc4randow()% (500-100+1) //100 + arc4random()%401 }

    6. 控件的复制

    NSData *archivedData = [NSKeyedArchiver archivedDataWithRootObject: myLabel1];
    
    UILabel *myLabel2 = [NSKeyedUnarchiver unarchiveObjectWithData: archivedData];
  • 相关阅读:
    Java 7 新的 try-with-resources 语句,自动资源释放
    单例模式在多线程下的问题
    设计模式-结构型模式
    设计模式-创建型模式
    【selenium】python+selenium+unittest,关于每次执行完一个测试用例都关闭浏览器等时间较长的问题之解决方案·续·装饰器
    【selenium】python+selenium+unittest,关于每次执行完一个测试用例都关闭浏览器等时间较长的问题之解决方案
    启动流程--CPU启动条件
    特殊估计制作(2): dump固件
    内存泄漏:lowmemory 相关调试
    寄存器调试 (2):应用层通过C代码访问
  • 原文地址:https://www.cnblogs.com/CoderWayne/p/3920018.html
Copyright © 2020-2023  润新知