You need handle touch event from you UIView. To do it you should create subclass of UIView and add your realisation of touchesBegan:withEvent: method, here simplest example:
// TouchSimpleView.h
@interface TouchSimpleView : UIImageView {
id delegate;
}
@property(retain) id delegate;
@end
@interface NSObject(TouchSimpleView)
-(void)didTouchView:(UIView *)aView;
@end
// TouchSimpleView.m
#import "TouchSimpleView.h"
@implementation TouchSimpleView
@synthesize delegate;
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touchesBegan!!! ");
if ( delegate != nil && [delegate respondsToSelector:@selector(didTouchView:)] ) {
[delegate didTouchView:self];
}
[super touchesBegan:touches withEvent:event];
}
@end
Then you can use views of this class when you want to handle touches, for example:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window makeKeyAndVisible];
touchView = [[TouchSimpleView alloc] initWithFrame:CGRectMake(50, 50, 200, 300)];
touchView.delegate = self;
[window addSubview:touchView];
imageView =[[UIImageView alloc] initWithFrame:touchView.frame];
imageView.image = [UIImage imageNamed:@"image1.png"];
[touchView addSubview:imageView];
}
-(void)didTouchView:(UIView *)aView{
NSLog(@"view touched, changing image");
imageView.image = [UIImage imageNamed:@"image2.png"];
}