1

我使用下面的代码来检测 UIImage 上的触摸

//

#import <UIKit/UIKit.h>

@interface KUIImageView : UIImageView
{


        CGPoint startLocation;
}
@end


@implementation KUIImageView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}
- (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

我在 touchesBegan 处设置断点

但是没有触发

UIImage 通过使用在 UIScrollView 上

[aScrollView addObject:aUIImageView];

欢迎任何评论

4

1 回答 1

0
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // here
        self.userInteractionEnabled = YES;
    }
    return self;
}
于 2012-05-10T08:36:01.487 回答