How to create buttons which are activated when the user slides their finger over them on iPhone

谁说胖子不能爱 提交于 2019-12-04 13:56:45

You can also use the function touchesBegan. With this function you can easily say what would happen if a button (or multiple buttons) are being pressed/touched.

Code should look like:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        UITouch *touch = [[event touchesForView:self.view] anyObject];

    if(touch == YourButton){
         //so some stuff after touching the button

    }
}

Don't forget to decare the button in your .h like IBOutlet UIButton * MyButton;

I haven't tried this up but try adding the newly added Gesture Recognizer to your button. Select the slide direction (Right/Left) and implement the [button setEnabled] function accordingly. Something like when the swipe happens, you set the button to be enabled and all other buttons to disable.

Peace

Buttons are not the way to go. UIViews have various touch methods that would work better. Or, use a custom gesture recognizer.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!