简体   繁体   English

长按内部动作表选项

[英]Longpress inside actionsheet options

Is it possible to use UILongPressGestureRecognizer inside the buttons of an actionsheet? 是否可以在操作表的按钮内使用UILongPressGestureRecognizer?

Shall I do different things, inside the action sheet if I touch or if I make long press? 如果触摸或长按,我是否应该在操作表内做其他事情?

Thanks 谢谢

YES you can 是的你可以

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

it will work just fine cheers 它会很好地工作

Either create your custom view which behave like ActionSheet. 创建您的自定义视图,其行为类似于ActionSheet。 Also try setting actionsheet delegate to nil in below mentioned code. 还可以尝试在下面提到的代码中将动作表委托设置为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");

}

this code will work for you if you want to add diffrent buttons with diffrent longpress than you have to add that "n" numbres of gestures cheers 如果您要添加带有不同longpress的不同按钮,而不是添加“ n”个手势欢呼,此代码将为您工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM