Quantcast
Viewing all articles
Browse latest Browse all 8068

Label appearing before animation completes

Hi guys,

Small issue with my app which is annoying me and my client.

The app has a view which shows Label1 initially, and then when the user taps the view it flips around and shows label2.

This works great the first time the function runs, but when you call the function again (on swipe), label 2 flashes up before the animation has completed.

Any ideas?

function loadWords() {
 
    // clear words first
    label1.text = '';
    label2.text = '';
 
    // get a random pair of words
    var db = Ti.Database.open('germanV5');
    var rows = db.execute('SELECT * FROM Words WHERE word_dropped = 0 ORDER BY RANDOM() LIMIT 1;');
 
    var x = 0;
    while (rows.isValidRow()) {
 
        if (selectedlanguage == 'en') {
            var word_1 = rows.fieldByName('word_english');
            var word_2 = rows.fieldByName('word_german');           
        } else if (selectedlanguage == 'de') {
            var word_2 = rows.fieldByName('word_english');
            var word_1 = rows.fieldByName('word_german');           
        }
 
        var word_id = rows.fieldByName('word_id');
 
        rows.next();
    }
 
    // close database
    rows.close();
 
    var state = true;
 
 
    win.add(masterView);
 
    var front = Ti.UI.createView({
        backgroundColor: '#FFF',
        top: 0,
        left: 0,
        width: 300,
        height: 140,
        opacity: 1.0,
        touchEnabled: false
    });
 
    label1.text = word_1;
 
    front.add(label1);
    masterView.add(front);
 
    var back = Titanium.UI.createView({
        backgroundColor: '#FFF',
        top: 0,
        left: 0,
        width: 300,
        height: 140,
        opacity: 1.0,
        touchEnabled: false
    });
 
    label2.text = word_2;
 
    back.add(label2);
 
    masterView.addEventListener('click', function (e) {
        switch (state) {
        case true:
            Ti.API.info('true');
            masterView.animate({
                view: back,
                transition: Ti.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT
            });
 
            break;
        case false:
            Ti.API.info('false');
            masterView.animate({
                view: front,
                transition: Ti.UI.iPhone.AnimationStyle.FLIP_FROM_RIGHT
            });
            break;
        }
        state = !state;
    });
 
 
    // event listener for the drop button
    dropButton.addEventListener('click', function (e) {
        // update the DB to tell it the word has been dropped
        //var dbDelete = Ti.Database.open('germanV5');
        //var rowsDelete = dbDelete.execute('UPDATE Words SET word_dropped=1 WHERE word_id='
        //+ word_id
        //);
 
 
        // pop an alert to notify the user the word has been dropped
        var alertDialog = Titanium.UI.createAlertDialog({
            title: 'Word Dropped',
            message: 'This word has been dropped!' + word_id,
            buttonNames: ['OK']
        });
        // show the message
        //alertDialog.show();
 
        // load in a new word
        //loadWords();
    });
 
 
}
iOS with Titanium 3.2.0

Many thanks

Simon


Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>