我使用下面的代码来检测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];
欢迎任何评论
答案 0 :(得分:0)
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// here
self.userInteractionEnabled = YES;
}
return self;
}