3

I want to make a certain section of my UIView clickable. When clicked, it triggers an IBAction, as would an UIButton.

How do I do this?

4

3 回答 3

3

在您的视图上添加自定义 UIButton,您需要点击的任何位置,然后对其执行操作。

    UIButton *button = [UIButton buttonWithType:0];
    [button setFrame:CGRectmake(0,0,0,0)]; //What ever clickable area, provide here
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
于 2013-02-01T05:43:07.463 回答
2

使用 UITapGestureRecognizer 并将透明按钮放在您希望可点击部分可用的区域上

于 2013-02-01T05:35:35.833 回答
0

添加UITapGestureRecognizer到您的UIView. 当您收到点击时,请检查您的识别器的locationInView:. 如果点击发生在您想要使点击敏感的区域,则触发操作;否则,忽略点击事件。

于 2013-02-01T01:16:38.087 回答