Note that there are some explanatory texts on larger screens.

plurals
  1. POFlipping a view in titanium like a card
    primarykey
    data
    text
    <p>I am using Titanium and running the emulator on iOS7. I am trying to get a card like flipping animation. I have it half way working. It will current flip from <code>front</code> to <code>back</code>, but as soon as I click it again, the app crashes and my console isn't showing anything.</p> <p>The docs say:</p> <p><code>The new view being transitioned to should NOT be a child of another view or of the animating view.</code></p> <p>Maybe I am understanding that wrong because I cannot seem to make this work. My code so far is:</p> <pre><code>var win = Ti.UI.currentWindow; var noThumbColors = ['#555555','#cccccc']; var noThumbColors2 = ['#ff0000','#000']; var views = []; var fronts = []; var backs = []; for (var i = 0; i &lt; 1; i++) { fronts[i] = Ti.UI.createView({ id:i, name:"front", width:150, height:150, backgroundGradient:{ type: 'linear', startPoint: { x: '0%', y: '0%' }, endPoint: { x: '0%', y: '100%' }, colors: [ { color: noThumbColors[0], offset: 0.0}, { color: noThumbColors[1], offset: 1.0 } ], }, currentAngle: 10 }); backs[i] = Ti.UI.createView({ id:i, name:"back", width:150, height:150, backgroundGradient:{ type: 'linear', startPoint: { x: '0%', y: '0%' }, endPoint: { x: '0%', y: '100%' }, colors: [ { color: noThumbColors2[1], offset: 0.0}, { color: noThumbColors2[0], offset: 1.0 } ], }, currentAngle: 10 }); win.add(backs[i]); win.add(fronts[i]); fronts[i].addEventListener('click', function(e) { log(e.source.name); t = Ti.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT; e.source.animate({view:backs[e.source.id],transition:t}); }); backs[i].addEventListener('click', function(e) { log(e.source.name); t = Ti.UI.iPhone.AnimationStyle.FLIP_FROM_RIGHT; e.source.animate({view:fronts[e.source.id],transition:t}); }); } function log(msg) { Ti.API.info(msg); } </code></pre> <h2><strong>The finished working code (will produce 3 squares that will flip back and forth independently):</strong></h2> <pre><code>var win = Ti.UI.currentWindow; var noThumbColors = ['#555555','#cccccc']; var noThumbColors2 = ['#ff0000','#000']; var containers = []; var fronts = []; var backs = []; for (var i = 0; i &lt; 3; i++) { containers[i] = Ti.UI.createView({ top:50 + (i * 155), width:150, height:150 }); fronts[i] = Ti.UI.createView({ id:i, name:"front", width:150, height:150, backgroundGradient:{ type: 'linear', startPoint: { x: '0%', y: '0%' }, endPoint: { x: '0%', y: '100%' }, colors: [ { color: noThumbColors[0], offset: 0.0}, { color: noThumbColors[1], offset: 1.0 } ], }, currentAngle: 10 }); backs[i] = Ti.UI.createView({ id:i, name:"back", width:150, height:150, backgroundGradient:{ type: 'linear', startPoint: { x: '0%', y: '0%' }, endPoint: { x: '0%', y: '100%' }, colors: [ { color: noThumbColors2[1], offset: 0.0}, { color: noThumbColors2[0], offset: 1.0 } ], }, currentAngle: 10 }); containers[i].add(backs[i]); containers[i].add(fronts[i]); win.add(containers[i]); } win.addEventListener('click', function(e) { if (e.source.name === "front") { containers[e.source.id].animate({view:backs[e.source.id],transition:Ti.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT}); } else if (e.source.name === "back") { containers[e.source.id].animate({view:fronts[e.source.id],transition:Ti.UI.iPhone.AnimationStyle.FLIP_FROM_RIGHT}); } }); function log(msg) { Ti.API.info(msg); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload