开发者

Getting Access to the touch event in an UIAlertView

开发者 https://www.devze.com 2023-01-21 07:13 出处:网络
I am displaying a Customized UIAlertView. I need to know how to get access to the touch events taking place in that AlertView.

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];
    //...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消