收录日期:2019/08/18 17:22:58 时间:2010-06-16 03:44:11 标签:objective-c,cocoa-touch,uibutton,ios

So I have my app working good when you press and drag along. I also have UIButtons set to Touch Down in Interface Builder.

As well when you drag you need to drag from the outside of the UIButton. You cannot click on the UIButton and drag to the other.

TOUCHES MOVED:

Code:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {

UITouch *touch = [[event touchesForView:self.view] anyObject];
CGPoint location = [touch locationInView:touch.view];

if(CGRectContainsPoint(oneButton.frame, location))
{
    if (!oneButton.isHighlighted){
        [self oneFunction];
        [oneButton setHighlighted:YES];
    }
}else {
    [oneButton setHighlighted:NO];
}
//
if(CGRectContainsPoint(twoButton.frame, location)) 
{
    if (!twoButton.isHighlighted){
        [self twoFunction];
        [twoButton setHighlighted:YES];
    }
}else {
    [twoButton setHighlighted:NO];
}

}

TOUCHES BEGAN:

Code:

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 

   UITouch *touch = [[event touchesForView:self.view] anyObject];

CGPoint location = [touch locationInView:touch.view];

if(CGRectContainsPoint(oneButton.frame, location))
{
    [self oneFunction];
    [oneButton setHighlighted:YES];
}
if(CGRectContainsPoint(twoButton.frame, location))
{
    [self twoFunction];
    [twoButton setHighlighted:YES];
}

}

I want to be able to click on any of the button fire the function & also be able to drag from one button on to the other and fire that function.

So basically just being able to click on a button and slide your finger over and activate the other button without having to press and slide from outside of the button.

I think I'm close, need a bit of help. Hope thats clear enough.

Thanks.

Tried something different. Using this worked much better:

if(CGRectContainsPoint(myObject.frame, location) && lastButton != myObject) {

Used it in touchesBegan & touchesMoved.