Iphone 仅允许在某些选定的视图标签上进行触摸事件

Iphone 仅允许在某些选定的视图标签上进行触摸事件,iphone,cocoa-touch,Iphone,Cocoa Touch,我是iPhone开发的新手,正在开发我的第一个应用程序 我在屏幕上有一些标签 在这些标签中,我必须在几个选定的标签上应用拖动事件 拖动的代码是 - (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { // Retrieve the touch point CGPoint pt = [[touches anyObject] locationInView:self]; startLocation =

我是iPhone开发的新手,正在开发我的第一个应用程序

我在屏幕上有一些标签

在这些标签中,我必须在几个选定的标签上应用拖动事件

拖动的代码是

- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
    // Retrieve the touch point
    CGPoint pt = [[touches anyObject] locationInView:self];
    startLocation = pt;
    [[self superview] bringSubviewToFront:self];
}

- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
    // Move relative to the original touch point
    CGPoint pt = [[touches anyObject] locationInView:self];
    CGRect frame = [self frame];
    frame.origin.x += pt.x - startLocation.x;
    frame.origin.y += pt.y - startLocation.y;
    [self setFrame:frame];
}
现在,我希望只将工具拖动到几个选定的标签上

我通过子类化UILabel实现了这一点

@interface DragView : UILabel
{
    CGPoint startLocation;
}
@end

@implementation DragView
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
    // Retrieve the touch point
    CGPoint pt = [[touches anyObject] locationInView:self];
    startLocation = pt;
    [[self superview] bringSubviewToFront:self];
}

- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
    // Move relative to the original touch point
    CGPoint pt = [[touches anyObject] locationInView:self];
    CGRect frame = [self frame];
    frame.origin.x += pt.x - startLocation.x;
    frame.origin.y += pt.y - startLocation.y;
    [self setFrame:frame];
}
@end
但是我想在没有子类化的情况下实现它

有什么方法可以做到这一点吗

您可以将
UILabel
的属性设置为
NO
您可以将
UILabel
的属性设置为
NO