Search code examples
titaniumtitanium-mobiletitanium-alloy

Titanium touchmove position


I have this in the view index.xml:

<Alloy>
    <Window class="container" fullscreen="true">
        <View id="accueil">
            <ImageView id="button_way"></ImageView>
        </View>
    </Window>
</Alloy>

and this in the controllers index.js

$.accueil.addEventListener("touchmove", function(e){
    Ti.API.info(e.y);
}); 

My problème are if i start click in the imageview and i move the absolute position are to the image view and not to the view.

I don't no why...

Can you help me, thanks, and sorry for my english.


Solution

  • The touchmove event's coordinates are always relative to the view in which the initial touch occurred.

    You need to convert the points in the image, to the points in the containing view, thankfully Titanium provides a helper method for that: convertPointToView

    I'm not sure exactly what you are trying to accomplish but here is an example of using this function, apply it to what you need to do:

    $.accueil.addEventListener("touchmove", function(e){
        // If the points are in the image, convert them to the containing view 
        if(e.source == $.button_way) {
            var imageViewPoint = { x e.x, y : e.y };
            // Translate from button_way to accueil point of view
            var accueilViewPoint = $.button_way.convertPointToView(imageViewPoint, $.accueil);  
            Ti.API.info(accueilViewPoint);   
        } else {
            // Otherwise just leave them
            var accueilViewPoint = { x e.x, y : e.y };
            Ti.API.info(accueilViewPoint);
        }
    });