user462407
user462407

Reputation: 3

objective-c disable drag in UIButton

I want to disable UIButton dragging in Xcode, is there anyway to do that?

any solution would help

Thanks

Upvotes: 0

Views: 1318

Answers (2)

user1802778
user1802778

Reputation: 81

You cannot disable touch drag events, but can use alternative of handling them. You need to handle Touch event handlers. When we swipe left or right TouchCancel event is fired and when you swipe up or down TouchDragExit is fired. Make sure to implement both.

@property (nonatomic) BOOL buttonFullyTouched; . . . //Touch Down Event

- (IBAction)filterTouchedDown:(id)sender
{    
    _nameButton.selected = NO;
    _codeButton.selected = NO;
    _dateButton.selected = NO;

    _filterFullyTouched = NO;
}

//Touch Drag Exit Event

- (IBAction)buttonDragExit:(id)sender
{
    if (!_buttonFullyTouched)
    {
        UIButton *randomButton = (UIButton *)[_groupView viewWithTag:_previousButtonSelectedTag + 2000];
        randomButton.selected = YES;
    }
}

// Touch Cancel Event

- (IBAction)buttonTouchCancel:(id)sender
{
    if (!_buttonFullyTouched)
    {
        UIButton *randomButton = (UIButton *)[_groupView viewWithTag:_previousButtonSelectedTag + 2000];
        randomButton.selected = YES;
    }
}

// TouchUpInside event

- (IBAction)groupButtonTapped:(id)sender
{
    _nameButton.selected = NO;
    _codeButton.selected = NO;
    _dateButton.selected = NO;

    _buttonFullyTouched = YES;

    // logic for further code
}

Upvotes: 1

joshpaul
joshpaul

Reputation: 953

If you're looking to disallow the user to drag-out from a touch, look at the UIControl class. Specifically take note of:

- (void)addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents

If you're using InterfaceBuilder, you should look at the options available for Events (in the Inspector window, second tab).

Upvotes: 0

Related Questions