iOS开发:触摸事件处理与表格视图设计
1. 绘制自定义视图
在iOS开发中,目前还未编写绘图代码,之前只是拦截了发送到视图的触摸事件,并提取了设备触摸状态的相关信息。在iOS里,并非在事件发生时就立即绘图,而是记录需要绘图的时机,等待iOS告知对象何时进行绘图。绘图由用户界面更新事件触发。
当iOS要求视图自行绘制时,对象会收到 -drawRect: 消息,以下是添加该消息的实现代码:
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
[[UIColor blackColor] set];
CGContextFillRect(context,rect);
UIBezierPath *path = nil;
if (touchPoints.count>1)
{
path = [UIBezierPath bezierPath];
NSValue* firstLocation = nil;
for ( NSValue *location in touchPoints )
{
if (firstLocation==nil)
{
firstLocation = location;
[path moveToPoint:location.CGPointVal
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



