Разрешить сенсорные события только на некоторых выбранных метках вида - PullRequest
1 голос
/ 17 декабря 2009

Я новичок в разработке для 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

но я хочу реализовать это без подкласса

есть ли способ сделать это

1 Ответ

4 голосов
/ 17 декабря 2009

Можно установить для свойства userInteractionEnabled UILabel значение NO.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...