2012-05-10 42 views
1

我用下面的代码来检测的UIImage的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
- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:frame]; 
    if (self) { 
     // here 
     self.userInteractionEnabled = YES; 
    } 
    return self; 
}