【发布时间】:2012-07-08 10:07:57
【问题描述】:
是否有Touch Up Inside 用于查看?
当用户点击或单击视图时,我想调用一个动作。
目前我在这个视图上使用了一个隐藏按钮,但这不是一个聪明的方法。
任何帮助表示赞赏:)
【问题讨论】:
-
添加手势识别器。可能的水龙头。
标签: iphone objective-c ios xcode ios5
是否有Touch Up Inside 用于查看?
当用户点击或单击视图时,我想调用一个动作。
目前我在这个视图上使用了一个隐藏按钮,但这不是一个聪明的方法。
任何帮助表示赞赏:)
【问题讨论】:
标签: iphone objective-c ios xcode ios5
你也可以像这样在 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
}
}
【讨论】:
我不明白为什么使用隐藏按钮不是一种聪明的方式......这是Apple自己建议的方式,我认为它很聪明,目前是更好的方式......
【讨论】:
如果您希望检测屏幕上没有按钮的任何位置的触摸,请使用- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event。您还可以像这样找到触摸的位置:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint *tLocation = [touch locationInView:self.view];
}
注意:touchesEnded 被称为 EVERY SINGLE TIME 视图被点击,所以上面的tLocation 将在用户每次触摸屏幕时改变。
【讨论】: