Launch a click in UIButton, but use touchsEnded in the main window

For example, I have a UIButton, which I posted in IB.

This function UIButtonhas two functions, depending on whether it has been touched inside or pulled out - it would be nice to at least maintain its operability for touching inward.

I want to click on my button and “drag out”, but use it -touchesEndedabove the rectangle when I finally release my click.

I know that one of the options is to cut UIButtonand use -touchesBeganthe mask, but it is a lot more effort and requires a good big rewrite (with 96 buttons in mind).

To paraphrase a little - I clicked on the button and clicked on the mouse, dragging the cursor (/ finger) to another point on my screen, and I want my view to recognize -touchesEndedwhen I finally release it. The problem is that the initial click is associated with the button, so it -touchesEndeddoesn’t happen in my main view ...

Am I trying to do it wrong? Also, am I clear?

EDIT: @Heckman formulated the question much lower

+3
source share
4 answers

If I understand your question correctly, you touch one button contained inside some UIView and want to pull out your finger and recognize the point in the button add-in.

, , , [UIButton superview], , , .

, - ( UIButton):

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [self.superview buttonPressed:self]
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [self.superview touchesEnded:touches withEvent:event];
}

( buttonPressed):

-(void) buttonPressed:(UIButton *) button {
    _buttonPressed = button;
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    if(self.buttonPressed) {
         //Process the release from your drag here. 
         for(UITouch * touch in touches) {
         //Use either of these to get the release position that you care about.
             CGPoint releaseLocationInCurrentView = [touch locationInView:self];
             CGPoint releaseLocationInButtonView = [touch locationInView:[self.buttonPressed]];
         }
    }
}
+2

- , iphone, TTLauncherView Three20. http://three20.info/showcase/launcher

0

, , :

UIButton touchdragexit IBAction

-(IBAction)dragPoint:(id)sender {

//Do Something Useful in here - I assign the value to an Array that I can recall when I touch up inside one of 16 buttons

//Now pass the button touch on as a touch up outside

[myButton addTarget:self action:@selector(dragBegan:withEvent:) forControlEvents: UIControlEventTouchUpOutside];
}

, dragBegan :

- (void)dragBegan:(UIControl *)c withEvent:ev {

UITouch *touch = [[ev allTouches] anyObject];
CGPoint touchPoint = [touch locationInView:self.view]; // Get location of the moment I release the touch (touch up outside)

//now some long convoluted code to give me the location of a row of 16 buttons, of which I would like to know which one I touched up inside

UIButton *posButton;
int pos;

if(628.00<(touchPoint.y) && (touchPoint.y)<664.00){
    if ((39.00<touchPoint.x && touchPoint.x<91.00) || (92.00<touchPoint.x && touchPoint.x<144.00) || (145.00<touchPoint.x && touchPoint.x<197.00) || (198.00<touchPoint.x && touchPoint.x<250.00)||(264.00<(touchPoint.x) && touchPoint.x<314.00)||(317.00<(touchPoint.x) && touchPoint.x<367.00)||(370.00<(touchPoint.x) && touchPoint.x<420.00)||(423.00<(touchPoint.x) && touchPoint.x<473.00)||(488.00<(touchPoint.x) && touchPoint.x<538.00) || (541.00<(touchPoint.x) && touchPoint.x<591.00) || (594.00<(touchPoint.x) && touchPoint.x<644.00) || (647.00<(touchPoint.x) && touchPoint.x<697.00)||(712.00<(touchPoint.x) && touchPoint.x<762.00)||(765.00<(touchPoint.x) && touchPoint.x<815.00)||(818.00<(touchPoint.x) && touchPoint.x<868.00)||(871.00<(touchPoint.x) && touchPoint.x<921.00)){


    if(39.00<(touchPoint.x) && touchPoint.x<91.00){
        posButton = SeqA;
        pos=0;

    }
    else if(92.00<(touchPoint.x) && touchPoint.x<144.00){
        posButton = SeqB;
        pos=1;

    }
    else if(145.00<(touchPoint.x) && touchPoint.x<197.00){
        posButton = SeqC;
        pos=2;

    }
    else if(198.00<(touchPoint.x) && touchPoint.x<250.00){
        posButton = SeqD;
        pos=3;

    }
        else if(264.00<(touchPoint.x) && touchPoint.x<314.00){
            posButton = SeqE;
            pos=4;

        }
        else if(317.00<(touchPoint.x) && touchPoint.x<367.00){
            posButton = SeqF;
            pos=5;

        }
        else if(370.00<(touchPoint.x) && touchPoint.x<420.00){
            posButton = SeqG;
            pos=6;

        }
        else if(423.00<(touchPoint.x) && touchPoint.x<473.00){
            posButton = SeqH;
            pos=7;

        }






        else if(488.00<(touchPoint.x) && touchPoint.x<538.00){
            posButton = SeqI;
            pos=8;

        }
        else if(541.00<(touchPoint.x) && touchPoint.x<591.00){
            posButton = SeqJ;
            pos=9;

        }
        else if(594.00<(touchPoint.x) && touchPoint.x<644.00){
            posButton = SeqK;
            pos=10;

        }
        else if(647.00<(touchPoint.x) && touchPoint.x<697.00){
            posButton = SeqL;
            pos=11;

        }

        else if(712.00<(touchPoint.x) && touchPoint.x<762.00){
            posButton = SeqM;
            pos=12;

        }
        else if(765.00<(touchPoint.x) && touchPoint.x<815.00){
            posButton = SeqN;
            pos=13;

        }
        else if(818.00<(touchPoint.x) && touchPoint.x<868.00){
            posButton = SeqO;
            pos=14;

        }
        else if(871.00<(touchPoint.x) && touchPoint.x<921.00){
            posButton = SeqP;
            pos=15;

        }

Now do something depending on the button you touched inside

Other things I did - I created a mask of the original UIButton as a UIImageView, which I made invisible on the touchdragoutside event (and reset on the above touchupinside), so that I have a button that I can drag

-1
source

All Articles