Lets say I wan\'t to add 1 to an integer. This will only be done when I push down on a UIButton
and then release my finger on another UIButton
.
// Create a button, add targets
UIButton *cloudButton = [UIButton buttonWithType:UIButtonTypeCustom];
[cloudButton setImage:[UIImage imageNamed:@"notification_add.png"] forState:UIControlStateNormal];
[cloudButton setFrame:CGRectMake(0, 0, 30, 30)];
[cloudButton addTarget:self action:@selector(dragBegan:withEvent: )
forControlEvents: UIControlEventTouchDown];
[cloudButton addTarget:self action:@selector(dragMoving:withEvent: )
forControlEvents: UIControlEventTouchDragInside | UIControlEventTouchDragOutside];
[cloudButton addTarget:self action:@selector(dragEnded:withEvent: )
forControlEvents: UIControlEventTouchUpInside |
UIControlEventTouchUpOutside];
[self.view addSubview:cloudButton];
//event methods
- (void) dragBegan: (UIControl *) c withEvent:ev
{
NSLog(@"dragBegan......");
}
- (void) dragMoving: (UIControl *) c withEvent:ev
{
NSLog(@"dragMoving..............");
}
- (void) dragEnded: (UIControl *) c withEvent:ev
{
NSLog(@"dragEnded..............");
}