Reputation: 5426
Assume that a five buttons side by side, I need to know how to make them accept (called) the drag from outside to inside the border of each button.
i.e. Like the piano if you drag your finger every button called and make sound
Upvotes: 2
Views: 1403
Reputation: 38475
You should add a handler for the 'drag enter' event for each button - I'm not sure that you can do this in interface builder but here's how to do it in code.
Put this in your viewDidLoad method :
[button1 addTarget:self action:@selector(buttonEntered:) forControlEvents:UIControlEventTouchDragEnter];
[button2 addTarget:self action:@selector(buttonEntered:) forControlEvents:UIControlEventTouchDragEnter];
[button3 addTarget:self action:@selector(buttonEntered:) forControlEvents:UIControlEventTouchDragEnter];
[button4 addTarget:self action:@selector(buttonEntered:) forControlEvents:UIControlEventTouchDragEnter];
[button5 addTarget:self action:@selector(buttonEntered:) forControlEvents:UIControlEventTouchDragEnter];
and then
- (void)buttonEntered:(UIButton *)button {
NSLog(@"Dragged into %@", button);
}
Have a look at this for the different types of control events you can listen for.
NB This example assumes that you have got this in your .h file :
@property (nonatomic, retain) IBOutlet UIButton *button1;
@property (nonatomic, retain) IBOutlet UIButton *button2;
@property (nonatomic, retain) IBOutlet UIButton *button3;
@property (nonatomic, retain) IBOutlet UIButton *button4;
@property (nonatomic, retain) IBOutlet UIButton *button5;
and connected them correctly in interface builder etc.
Upvotes: 2