I am displaying a Customized UIAlertView. I need to know how to get access to the touch events taking place in that AlertView.
I have a controller class which is set as the delegate of my customized UIAlertView, with the following method, but this is not triggered on touching being taking place in AlertVi开发者_运维知识库ew.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
Another solution (instead of overriding UIView and - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
) could be the usage of UIGestureRecognizer.
UIGestureRecognizers are very powerful and worth a look anyway.
In this case you don't have to deal with inheritance, but can add it to any view.
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(tapGestureDetected:)];
[self addGestureRecognizer:tapRecognizer];
}
return self;
}
- (void) tapGestureDetected:(UITapGestureRecognizer*)recognizer {
int numberOfTapAreas = [self.delegate numberOfTabAreas];
CGPoint p= [tapRecognizer locationInView:recognizer.view];
//...
}
精彩评论