[英]How to recognize which button is pressed on the view after an UILongPressGestureRecognizer
I want to capture the frame
or some proprieties(a frame or tag
of a UIButton
in this case) after a UILongPressGestureRecognizer
is fired.我想在触发
UILongPressGestureRecognizer
后捕获frame
或某些UILongPressGestureRecognizer
(在这种情况下是UIButton
的框架或tag
)。
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?是否有任何方法可以识别点击/选择的最后一个元素是什么?
在你setProductToButton
法, recognizer.view
属性是被按下的按钮。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.