objective-c disable drag in UIButton
I want to disable UIButton dragging in Xcode, is there anyway to do that?
any solution w开发者_开发知识库ould help
Thanks
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
}
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).
精彩评论