private void toTouchEvents (long touches, UIEvent uiEvent) {
long array = NSSetExtensions.allObjects(touches);
int length = (int) NSArrayExtensions.count(array);
for (int i = 0; i < length; i++) {
long touchHandle = NSArrayExtensions.objectAtIndex$(array, i);
UITouch touch = UI_TOUCH_WRAPPER.wrap(touchHandle);
CGPoint loc = touch.getLocation(touch.getView());
synchronized(touchEvents) {
UITouchPhase phase = touch.getPhase();
TouchEvent event = touchEventPool.obtain();
event.x = (int)(loc.x() * app.displayScaleFactor);
event.y = (int)(loc.y() * app.displayScaleFactor);
event.phase = phase;
event.timestamp = (long)(touch.getTimestamp() * 1000000000);
touchEvents.add(event);
if(phase == UITouchPhase.Began) {
event.pointer = getFreePointer();
touchDown[event.pointer] = (int) touch.getHandle();
touchX[event.pointer] = event.x;
touchY[event.pointer] = event.y;
deltaX[event.pointer] = 0;
deltaY[event.pointer] = 0;
numTouched++;