在我的应用程序中,我在 uiscrollview 中添加 uibuttons 作为 subview 。我想在长按时获得按钮的标签。我的代码是
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(handleLongPress:)];
longPress.minimumPressDuration = 2.0;
longPress.delegate = self;
[gridScrollView addGestureRecognizer:longPress];
我想知道如何在这段代码中获取特定的按钮标签
-(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer {
}
最佳答案
您将从 subviews 属性中获取所有按钮
for (UIButton *eachBtn in [gridScrollView subviews]) {
if ([eachBtn isKindOfClass:[UIButton class]]) {
NSLog(@"Button Tag : %i",eachBtn.tag);
}
}
如果要传递按钮的标签,则将相同的标签设置为手势
longPress.view.tag = btn.tag
之后在您的长按处理程序方法中获取此标签
NSLog(@"Button Tag : %i",longPress.view.tag);
关于ios - 获取长按时在 UIScrollView 中添加的 UIButtons 的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23562058/