“保持”UIButton行为 - “触摸取消”控制状态阻止进一步的控制状态 [英] 'Hold' UIButton Behaviour - `Touch Cancelled` Control State blocking further control states

查看:133
本文介绍了“保持”UIButton行为 - “触摸取消”控制状态阻止进一步的控制状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在子视图视图上有一个按钮(为了讨论,子视图是一个红色方块),当用户按住按钮时,红色方块会变成半透明。

I have a button on a subview view (for talk sake the subview is a red square) that when the user holds down on the button the red square animates translucent.

我有按钮连接到此方法:

I have the button connected to this method:

-(IBAction)peekToggle:(id)sendr{        

    NSLog(@"TOGGLE");

    if(self.view.alpha ==1)self.view.alpha = 0.1;   
    else self.view.alpha = 1;       
}

通过行为: c $ c>,外面触摸触摸。所以当我按住按钮,红色的盒子走向平直,当我释放我的手指,它回到不透明。
这最初工作正常,但是如果我按住按钮超过1秒钟,按钮不会注册触摸(释放手指)。

Via the behaviours: touch up inside, touch up outside and touch down. so when i hold the button down the red box goes transluscent and when i release my finger it returns to opaque. This initially works fine, however if i hold the button down for more than 1 second, the button does not register the touch up (release of the finger).

注意:我在父视图(子视图的父视图不是Button的父视图)上有一个longPressGestureRecogniser,但没有被触发(预期)。

NB:I do have a longPressGestureRecogniser on the parent view (parent of subview not parent of Button) but its not being fired (expected).

我很确定我长按按钮被注册为触摸取消,然后使触摸up事件无效。

Im pretty sure my long press on the button being registered as a touch cancel and then invalidating the touch up event.

如何防止/解决此问题?

How can I prevent/work around this?

我可以停止触摸取消射击? (该事件似乎触发,即使我已经注册了控制状态)或在触摸取消事件,告诉按钮保持/开始注册事件?

Can I Stop the touch Cancel Firing? (this event seems to fire even if i havant registered the control state) or in the touch Cancel event, tell the button to keep/start registering events?

推荐答案

解决方案:

完全移除IBActions UILongPressGestureRecognizer 按钮

Removed the IBActions completely and added UILongPressGestureRecognizer to the button with a very short min duration.

    UILongPressGestureRecognizer * recognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleGesture:)];    
        recognizer.minimumPressDuration = 0.1;  
        [self.peekButton.view addGestureRecognizer:recognizer];
        [recognizer release];

然后在gr的选择器中读取gr的状态:

Then in the selector for the gr, read the gr's state:

    - (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer{ 

        //1 = start
        if(gestureRecognizer.state==1 || gestureRecognizer.state==3)[self peekToggle];
        //3=end
}

这篇关于“保持”UIButton行为 - “触摸取消”控制状态阻止进一步的控制状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆