Ios 在drawRect中的图形项目上添加触摸事件

Ios 在drawRect中的图形项目上添加触摸事件,ios,iphone,objective-c,drawrect,Ios,Iphone,Objective C,Drawrect,我正在制作一个日历应用程序。现在我像这样在屏幕上画出我的约会 if (boolMark) { UIColor *blueColorMark = [UIColor colorWithRed:0 green:.62 blue:.984 alpha:0.5]; appointmentRect.origin.x += 5; appointmentRect.size.width -= 10; NSArray *appointments = [

我正在制作一个日历应用程序。现在我像这样在屏幕上画出我的约会

if (boolMark) {
        UIColor *blueColorMark = [UIColor colorWithRed:0 green:.62 blue:.984 alpha:0.5];
        appointmentRect.origin.x += 5;
        appointmentRect.size.width -= 10;
        NSArray *appointments = [[mark valueForKey:@"appointments"] mutableCopy];
        float lblHeight = appointmentRect.origin.y - tileHeightAdjustment + 20;
        for (NSDictionary *appointment in appointments){
            UIImage *overlayImage=[self imageWithColor:blueColorMark];
            NSString *strTitle = [NSString stringWithFormat:@"%@",[appointment valueForKey:@"app_label"]];
            if (forIpad) {
                NSLog(@"AppointmentRect Y = %f",lblHeight);
                appointmentRect.origin.y = lblHeight;
            }
            else
            {
                appointmentRect.origin.y -= 6;
            }
            appointmentRect.size.height = [self calculateHeight:strTitle andWidth:appointmentRect.size.width];
            lblHeight += appointmentRect.size.height + 5;

            [overlayImage drawInRect:appointmentRect];
            UIFont *f3 =[UIFont fontWithName:@"MyriadPro-Regular" size:10];
            [strTitle drawInRect: appointmentRect
                   withFont: f3
              lineBreakMode:NSLineBreakByWordWrapping
                  alignment: NSTextAlignmentCenter];


        }
    }
现在,我希望当用户触摸某个约会时,显示一个详细视图,其中包含有关该约会的更多信息

我现在的问题是,当用户点击某个约会(某个重叠图像)时,如何设置操作

有什么帮助吗

亲切问候

几件事:

如果您将约会解析为一个模型类
Appointment
,则会更容易。 在绘制每个约会之前,先计算每个约会视图的rect,然后可以将该数据存储在一组字典中,以备以后使用,类似这样的方法

@[@{@"appointmentKey" : appointmentObject1, @"frameKey" : [NSValue valueWithCGRect:calculatedRect1]},
  @{@"appointmentKey" : appointmentObject2, @"frameKey" : [NSValue valueWithCGRect:calculatedRect2]}];
  • 稍后,您将使用此选项绘制并找到正确的约会
  • 制作一个方法
    Appointment*appointmentForPoint:(CGPoint)
    ,它迭代上层数组中的所有字典并检查
    CGRectContainsPoint(rect,point)
    ;如果为true,则返回与该词典关联的约会
  • 将轻触手势识别器添加到视图中,并调用
    appointmentForPoint:
    以获得正确的约会