点击/单击查看操作Xcode

ph3*_*3nx 3 iphone xcode objective-c ios ios5

Touch Up Inside意见吗?我想在用户点击或点击视图时调用操作.目前我在这个视图上使用了一个隐藏按钮,但这不是一个聪明的方法.

任何帮助表示赞赏:)

Cli*_*udo 8

那你也可以在UIView上使用addGestureRecognizer方法,如下所示:

// In some View controller
UITapGestureRecognizer *tapGR;
tapGR = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)] autorelease];
tapGR.numberOfTapsRequired = 1;
[myUIView addGestureRecognizer:tapGR];

// Add a delegate method to handle the tap and do something with it.
-(void)handleTap:(UITapGestureRecognizer *)sender
{
    if (sender.state == UIGestureRecognizerStateEnded) {
        // handling code
    }
}
Run Code Online (Sandbox Code Playgroud)