触摸绘图学习笔记

今晚看了《iPhone开发秘籍》第8章,还没有看手势部分,记录下列收获。

 

1、对于视图内的多个小目标控件,要想点击时显示在其他控件前面,就在控件视图类的TouchesBegan:函数中调用“[[self superview] bringSubviewToFront: self];”

2、在视图中添加多个小图像控件:

- (void) viewDidLoad
{
	self.navigationController.navigationBar.tintColor = COOKBOOK_PURPLE_COLOR;
	srandom(time(0));
	
	for (int i = 0; i < MAXFLOWERS; i++)
	{
		NSString *whichFlower = [[NSArray arrayWithObjects:@"blueFlower.png", @"pinkFlower.png", @"orangeFlower.png", nil] objectAtIndex:(random() % 3)];
		DragView *dragger = [[DragView alloc] initWithImage:[UIImage imageNamed:whichFlower]];
		dragger.center = randomPoint();
		[self.view addSubview:dragger];
		[dragger release];
	}
}
@end

3、在多点触摸时,可以有多个小视图同时获得TouchesBegan:消息,这样就可以同时拖动多个控件

4、视图的.center坐标属性是绝对坐标,相对于Frame窗口的左上角;在视图的绘图上下文中绘图时是以当前视图的左上角的。

5、绘图得到图像,进而创建出图像控件:

- (UIImage *) createImage
{
	UIGraphicsBeginImageContext(CGSizeMake(cx, cy));
	CGContextRef context = UIGraphicsGetCurrentContext();
		……	
	UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
	UIGraphicsEndImageContext();
	return theImage;
}
DragView *dragger = [[DragView alloc] initWithImage:[self createImage]];
posted @ 2011-10-23 22:54  张云贵  Views(461)  Comments(0Edit  收藏  举报