如何在 UILongPressGestureRecognizer 之后识别视图上按下了哪个按钮
我想在 UILongPressGestureRecognizer
之后捕获 frame
或一些属性(在本例中是 UIButton
的框架或 tag
) code> 被解雇。
这是我的代码片段:
...create the uibutton (btn instance)
//add gesture to button
UILongPressGestureRecognizer *twoSecPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(setProductToButton:)];
[twoSecPress setMinimumPressDuration:2];
[btn addGestureRecognizer:twoSecPress];
[twoSecPress release];
btn.tag=INDEX;
这是方法:
- (void)setProductToButton:(UILongPressGestureRecognizer *)recognizer {
if (recognizer.state == UIGestureRecognizerStateBegan) {
for (UIButton *selButt in [self.scrollView subviews]) {
if(selButt.selected){//THIS IS ALWAYS FALSE
NSLog(@"%d",selButt.tag);
}
}
}
}
看来按钮的状态仍然没有改变。 有什么建议吗?
有没有任何方法可以识别最后点击/选择的元素是什么?
I want to capture the frame
or some proprieties(a frame or tag
of a UIButton
in this case) after a UILongPressGestureRecognizer
is fired.
this is my snippet:
...create the uibutton (btn instance)
//add gesture to button
UILongPressGestureRecognizer *twoSecPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(setProductToButton:)];
[twoSecPress setMinimumPressDuration:2];
[btn addGestureRecognizer:twoSecPress];
[twoSecPress release];
btn.tag=INDEX;
and this is the method:
- (void)setProductToButton:(UILongPressGestureRecognizer *)recognizer {
if (recognizer.state == UIGestureRecognizerStateBegan) {
for (UIButton *selButt in [self.scrollView subviews]) {
if(selButt.selected){//THIS IS ALWAYS FALSE
NSLog(@"%d",selButt.tag);
}
}
}
}
It seems that the state of the button still has not changed.
Any suggestion?
Are there any methods to recognize what is the last element tapped/selected?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
setProductToButton
方法中,recognizer.view
属性是按下的按钮。In your
setProductToButton
method, therecognizer.view
property is the button that was pressed.