【发布时间】:2015-05-25 10:17:43
【问题描述】:
是否可以在操作表的按钮内使用 UILongPressGestureRecognizer?
如果我触摸或长按,我应该在操作表内做不同的事情吗?
谢谢
【问题讨论】:
标签: ios objective-c xcode
是否可以在操作表的按钮内使用 UILongPressGestureRecognizer?
如果我触摸或长按,我应该在操作表内做不同的事情吗?
谢谢
【问题讨论】:
标签: ios objective-c xcode
是的,你可以
UIActionSheet *action = [[UIActionSheet alloc]initWithTitle:@"title" delegate:(id)self cancelButtonTitle:@"ok" destructiveButtonTitle:@"option" otherButtonTitles:nil, nil];
[action showInView:self.view];
UILongPressGestureRecognizer *longtaped = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(recog)];
[action addGestureRecognizer:longtaped];
它会工作得很好 干杯
【讨论】:
要么创建您的自定义视图,其行为类似于 ActionSheet。还可以尝试在下面提到的代码中将 actionsheet 委托设置为 nil。
-(void)AddactionSheet{
UIActionSheet *action = [[UIActionSheet alloc]initWithTitle:@"title" delegate:(id)self cancelButtonTitle:@"ok" destructiveButtonTitle:@"option" otherButtonTitles:nil, nil];
[action showInView:self.view];
for(UIView *v in [action subviews])
{
if([v isKindOfClass:[UIButton class]] )
{
//((UIButton*)v).backgroundColor = [UIColor redColor]; // change button color
UILongPressGestureRecognizer *longtaped = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(recog)];
[((UIButton*)v) addGestureRecognizer:longtaped];
}
}
}
-(void)recog{
NSLog(@"Longpressed");
}
此代码将为您工作 如果您想使用不同的长按添加不同的按钮,则必须添加“n”个手势 干杯
【讨论】: