0
votes

I'm trying to call these Methods on some event:

        -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

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

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

But i don't know how to fill the parameters : 1 - (NSSet *)touches 2 - withEvent:(UIEvent *)event

Can any one provide me with a sample parameters do call to (void)touchesEnded and (void)touchesMoved: (and - (void)touchesBegan

2
What are you trying to achieve? There's likely an easier way.Sergey Kalinichenko
"can you explain more?" -- Setting up and sending touches on a button click is an unusual solution. If you could edit your question and explain what is the end result that you are trying to implement, there may be a solution that does not involve calling touchesXXX:withEvent:.Sergey Kalinichenko
i just want to call these methods and i want to put new parameters ..forget the button click..Reham
you're question is unclear.... you want to call these methods when you press a button? There is something called -(IBAction) also you can't manually call a touch event.... i don't understand... a touch event is called when you touch....MCKapur

2 Answers

0
votes

There's no public constructors for UITouch and UIEvent, so you cannot generate the parameters required by the touch method.

As dasblinkenlight said, there could be surely another approach to your problem. But, the current approach is absolutely not possible.

0
votes

Those methods are called automatically by the system. You never call them directly.

What you should do, well that depends on your goal. If you just want to "simulate" touches, just have helper methods. Then, have touchesXXXX call those directly.

We do not get an API to create UITouch objects, so you have to mirror them if you want to keep their information around. Something like...

@interface MyTouch : NSObject {
UITouchPhase phase
NSUInteger tapCount
NSTimeInterval timestamp
UIView *view
UIWindow *window
CGPoint locationInView;
CGPoint locationInWindow;
@end

Then, you could have a method like this...

- (void)handleTouches:(NSSet*)touches {
}

Where touches was a set of MyTouch objects.

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    // For UITouch in touches, create a MyTouch, and add it to your own
    // collection of touches.

    [self handleTouches:myTouches];
}

If you did this for each touchesXXXX method, each one of them pass off handling to your own method.

Now, by doing this, you have control over creating your own touch objects. You can make them be configured for any view, or pattern you want. Then, in any other piece of code, you can create a collection of MyTouch objects, and call handleTouches: with them.

As long as the touchesXXXX methods just create your special objects, and pass them on to your method, you can have the exact same behavior whether the system generates the touches, or you simulate them.

Now, what you DO NOT get is automatic generation of system events.

If you are getting killed by the performance of that, there are simple ways to avoid the creation of the extra set and objects, but that's not your question.