-1

I need to copy a UIEvent in order to forward it to a UIView (UIWebView) at a later time. Is this possible? And if so, how can I achieve it?

example subclass of main UIWindow

UIEvent *startEvent;

- (void)sendEvent:(UIEvent *)event {
NSSet *touches = [event allTouches];
UITouch *touch = touches.anyObject;
if(touch.phase == UITouchPhaseBegan) {
        startEvent = event; //will only point startEvent to event so startEvent changes each time event changes, but I need to keep the original event when UITouchPhaseBegan.
       //startEvent = [event copy]; //i tried that, but unfortunately it's not working
}

Has anyone done this before and found a solution that will not cause the app to be rejected by Apple? ....

user3159270
  • 119
  • 2
  • 10
  • What's wrong with keeping a reference to this event? Are event objects re-used in some unconventional manner? – trojanfoe Jul 16 '14 at 09:47
  • I want to keep the start event (when UITouchPhaseBegan) in startEvent and forward it to another view at a later time. But at a later time event might have changed (for example to UITouchPhaseEnded) and if I forward startEvent at this time it also has UITouchPhaseEnded. – user3159270 Jul 16 '14 at 09:56
  • How do you mean "changed"? – trojanfoe Jul 16 '14 at 09:59
  • changed in that way that the touchevent of startEvent also has UITouchPhaseEnded by then ... I need the event when it was UITouchPhaseBegan – user3159270 Jul 16 '14 at 10:32
  • So you are saying the `UIEvent` object is re-used and new ones aren't created for each event? (genuine question; I haven't looked into it). – trojanfoe Jul 16 '14 at 10:35
  • exactly, startEvent acts as a pointer to event which is what I have to solve – user3159270 Jul 16 '14 at 10:36
  • 1
    Well I would say forget about copying the `UIEvent` and take whatever it is you want from it and then send only that information to the view later on. – trojanfoe Jul 16 '14 at 10:39
  • :-) I would do it if it was what I wanted. Unfortunately I need a UIEvent. Because I can only forward a UIEvent. So the question is: Is there a way to copy a UIEvent? – user3159270 Jul 16 '14 at 12:10
  • 1
    From the docs: "A UIEvent object representing a touch event is persistent throughout a multi-touch sequence; UIKit reuses the same UIEvent instance for every event delivered to the application. You should never retain an event object or any object returned from an event object. If you need to keep information from an event around from one phase to another, you should copy that information from the UITouch or UIEvent object." – Carl Veazey Jul 16 '14 at 12:20

1 Answers1

0

AppDelegate *delegate = [UIApplication sharedApplication].delegate; UIWindow *window = delegate.window;

[window sendEvent:_event];

Yes you can send event to window but you can not create your own event like Touch event.

And you can not tell window how to handle that event