Longpress内部的动作表选项

时间:2015-05-25 10:17:44

标签: ios objective-c xcode

是否可以在动作表的按钮中使用UILongPressGestureRecognizer?

如果我触摸或长按,我可以在活动表中做不同的事情吗?

由于

2 个答案:

答案 0 :(得分:1)

是的,你可以

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];

它会正常工作 欢呼声

答案 1 :(得分:1)

创建与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”个手势 欢呼声