Thursday, March 12, 2009

Obj-C tutorial

One Obj-C tutorial for beginners:

http://cocoadevcentral.com/d/learn_objectivec/

尤其是对Memory Management的论述十分到位。

Tuesday, March 10, 2009

一个下载技术类电子书的网站

http://www.itpub.net

非常好,注册之后就可以下载,一口气下载了所有iPhone dev相关的书。

Monday, March 9, 2009

NSTimer

-(void)startTimer {
        frameTimer = [NSTimer scheduledTimerWithTimeInterval:TIMER_INTERVAL
                  target:self
                  selector:@selector(handleTimer:)
                  userInfo:nil
                  repeats:YES];
}
-(void)stopTimer {
        if (frameTimer != nil) {
                [frameTimer invalidate];
                frameTimer = nil; //note
        }
}

- (void)handleTimer: (NSTimer *) timer
{
        whichFrame ++;
        [self setNeedsDisplay];
}

Sunday, March 8, 2009

UIView

- [rootView addSubView:newView]

newView 将被添加到 [[rootView subViews] count]处。
举个例子,如果rootView已经有3个subview,当 addSubView操作后,rootView含有4个subview,最后一个subview为刚刚被添加的newView。最新被添加的view处于屏幕的最前面。

下面的代码将最后一个subview从subviews中删除:
[[[rootView subviews] objectAtIndex:[[rootView subViews] count]-1] removeFromSuperview];

- 给view加个标签
setTag可以给view加上标签,这样就可以很容易取回想要view:viewWithTag


Saturday, March 7, 2009

UIImage

UIImage   *bgImage = [UIImage imageNamed:@"ume_bg.png"]; // 320*480 PNG

CFDataRef bgImageData = CGDataProviderCopyData(CGImageGetDataProvider(bgImage.CGImage));


//int length = CFDataGetLength(bgImageData); //480*320*3

//size_t height = CGImageGetHeight(bgImage.CGImage); //480

//size_t width =  CGImageGetWidth(bgImage.CGImage);  //320

//size_t a1 = CGImageGetBitsPerComponent(bgImage.CGImage); //8

//size_t a2 = CGImageGetBitsPerPixel(bgImage.CGImage); //24 = 8 * 3(R G B)

//size_t a3 = CGImageGetBytesPerRow(bgImage.CGImage); //960 = 320 * 3(R G B)

const UInt8 *bgByte = CFDataGetBytePtr(bgImageData); // raw data


// get RGB data at position pos

int r = bgByte[pos];

int g = bgByte[pos+1];

int b = bgByte[pos+2];


/*

NSString *msg = [[NSString alloc] initWithFormat:@"pos(x:%d, y:%d) (%d, %d, %d)", xx, yy, r, g, b];

UIAlertView *alert = [[UIAlertView alloc]

initWithTitle:@"(x,y)"

message:msg

delegate:self

cancelButtonTitle:@"Phew!"

otherButtonTitles:nil];

[alert show];

[msg release];

[alert release];

*/

/*

UIImageView *umeView = [[UIImageView alloc] initWithFrame:CGRectMake(point.x, point.y-31, 42.0, 62.0)];

//load all the frames of ume animation

umeView.animationImages = [NSArray arrayWithObjects:

[UIImage imageNamed:@"ume_1.PNG"],

[UIImage imageNamed:@"ume_2.PNG"],

[UIImage imageNamed:@"ume_3.PNG"], nil];

umeView.animationDuration = 0.5;

umeView.animationRepeatCount = 0;

[umeView startAnimating];

[self.view addSubview:umeView];

[umeView stopAnimating];

[umeView release];

*/

写书的打算

又和出版社的朋友聊了一下,打算用三个月的时间出一本书。内容是iPhone SDK开发相关的东西。有写书的想法已经很久了,原来就是想纪录下自己平时做开发时的一些东西,一来可以记录每天的进度,二来可以给后来者以参考,让他们少走弯路。

3月7号,I have a plan.

Sunday, March 1, 2009

Status Bar

- status bar在屏幕的最顶端,占据20个像素的高度

- 怎样隐藏status bar:
方法一:在info.plist新增加一项,key=UIStatusBarHidden 鼠标右键“value Type"->"Boolean"然 后把value中的box选中。

方法二:[UIApplication sharedApplication]
setStatusBarHidden:YES animated:NO]