2

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.

Jeff Kelley
  • 19,021
  • 6
  • 70
  • 80
AndrewDK
  • 165
  • 2
  • 4
  • 8
  • The best place for this is in objective-c and not c. – BobbyShaftoe Jun 16 '10 at 03:34
  • That code looks good. What isn't it doing that you want it to? – Jeff Kelley Jun 16 '10 at 03:45
  • @Jeff The thing that doesnt work is that when I hit one of the UIButton I can slide my finger to another one to fire that function. I have to slide my finger from outside any of the UIButtons. – AndrewDK Jun 16 '10 at 13:36
  • Where are these methods? A view controller? – Jeff Kelley Jun 16 '10 at 13:58
  • Yes its inside a UIViewController - MainViewController : UIViewController which is pulled through my RootViewController which assign that view as the first. MainWindow.xib -> MainView.xib So yes its in a View Controller. – AndrewDK Jun 16 '10 at 14:10

1 Answers1

1

Tried something different. Using this worked much better:

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

Used it in touchesBegan & touchesMoved.

AndrewDK
  • 165
  • 2
  • 4
  • 8