3.04~设置屏幕常亮、TableView小bug~

1、UITableView调用cellForRowAtIndexPath:返回空的情况

[UITableView cellForRowAtIndexPath:index];//如果想要返回的cell并未被显示(绘制)则会返回为空,那么需要想方设法促使cell被绘制,例如调用下面的方法:

[mTableDevices scrollToRowAtIndexPath:index atScrollPosition:UITableViewScrollPositionNone animated:NO]; //animated:NO必须是NO,否则selectRowAtIndexPath如果选择中未被绘制的cell将会返回空

 

2、UIView的放大缩小

#import <QuartzCore/QuartzCore.h>

.......

CGAffineTransform可以用来完成UIVIew的各种缩放翻转,如下定义

A structure for holding an affine transformation matrix.

struct CGAffineTransform {

   CGFloat a;

   CGFloat b;

   CGFloat c;

   CGFloat d;

   CGFloat tx;

   CGFloat ty;

};

typedef struct CGAffineTransform CGAffineTransform;

CGAffineTransform

 

//UIView放大

UIView *view = ...;

CGAffineTransform trans = CGAffineTransformScale(self.transform, 1.5, 1.5);

view.transform = trans;

//缩小到放大前的状态

CGAffineTransform trans = CGAffineTransformInvert(self.transform);  //详见CGAffineTransformInvert函数定义

    /*

    trans = {

        a = 0.666667    //0.666667 = 1 - 1/1.5, 1.5即之前放大倍数的倒数, 1.5 * a = 1,才能回到之前的大小状态

        b = -0

        c = -0

        d = 0.666667

        tx = 0

        ty = 0

    } */

    CGAffineTransform newTransform = CGAffineTransformConcat(self.transform, trans);  //两两相乘

//    CGAffineTransform newTransform = CGAffineTransformMake(1.0, 0, 0, 1.0, 0, 0);     //两个newTransform的值是一样的

    self.transform = newTransform;

3.程序是启动状态时设置屏幕一直亮 
    UIApplication *appDelegate = [UIApplicationsharedApplication];
    appDelegate.idleTimerDisabled =YES;

 

4.如何用UIColor生成UIImage

[plain] view plaincopyprint?
- (void)viewDidLoad   
{
    [superviewDidLoad];  
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10,10,100,100)];  
    UIImage *image = [self createImageWithColor:[UIColoryellowColor]];   //生成一张黄颜色的图片    
    [imageViewsetImage:image];   
    [self.viewaddSubview:imageView]; 
    [imageViewrelease];  
}    
- (UIImage *) createImageWithColor: (UIColor *) color 
{   
    CGRect rect = CGRectMake(0.0f,0.0f,1.0f,1.0f);   
   UIGraphicsBeginImageContext(rect.size);   
   CGContextRef context =UIGraphicsGetCurrentContext();  
   CGContextSetFillColorWithColor(context, [colorCGColor]);  
    CGContextFillRect(context, rect);   
   UIImage *theImage =UIGraphicsGetImageFromCurrentImageContext();  
   UIGraphicsEndImageContext();   
    return theImage;   
}  

posted @ 2013-03-04 14:09  痴人指路  阅读(192)  评论(0编辑  收藏  举报