【发布时间】:2012-01-26 16:14:08
【问题描述】:
我有以下问题。我有一个UIScrollView,上面有几个按钮,这些按钮上的图标设置为图像。我有一个长按识别器连接到每个按钮。如何在长按手势的发件人按钮上显示较小的删除图标?我的目标是创建当用户想要删除特定应用程序时 iOS 呈现的行为。
这是按钮的代码(带图像):
//set the button with the image of conference here.
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(3, 3, w-5, h-5);
CALayer * l = [button layer];
[l setMasksToBounds:YES];
[l setCornerRadius:8.0];
[button setImage:thumb forState:UIControlStateNormal];
button.property = confInfo;
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
button.tag = i;
bView.tag = i;
//Add gesture recognizer to be used for deletion of conference.
UILongPressGestureRecognizer *pahGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressGestureRecognizerStateChanged:)];
pahGestureRecognizer.minimumPressDuration = 1.0;
[button addGestureRecognizer:pahGestureRecognizer];
这段代码在一个循环中(见代码中的 i)。我的长按动作是这样的:
- (void)longPressGestureRecognizerStateChanged:(UIGestureRecognizer *)gestureRecognizer {
switch (gestureRecognizer.state) {
case UIGestureRecognizerStateEnded:
NSLog(@"Tapped!!!");
break;
default:
break;
}
}
如何将单击的按钮传递给此操作,以在按钮的右上角显示较小的 X 图像?
【问题讨论】:
标签: ios uibutton uiimage uigesturerecognizer