Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-13666] iOS: switching between views with animate fails after the first attempt

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionInvalid
Resolution Date2013-09-23T19:14:03.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsiOS
Labelsn/a
ReporterDavide Cassenti
AssigneeIngo Muschenetz
Created2013-04-24T16:28:58.000+0000
Updated2017-03-22T21:05:23.000+0000

Description

Description of the problem

When switching between views using animate, the operation works (back and forth) only once.

Steps to reproduce

Use the following code, switch to view 2, back to view 1, and again: it will only work once, then back to view1 it will not go anymore to view2.
function createView1() {
	var view1 = Ti.UI.createView();
	
	var btn1 = Ti.UI.createButton({
		title: 'Switch to view2'
	});
	btn1.addEventListener('click', function() {
		var view2 = createView2();
		view1.animate({view: view2, transition: Ti.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT});
	});
	view1.add(btn1);
	
	return view1; 
}

function createView2() {
	var view2 = Ti.UI.createView();
	
	var btn2 = Ti.UI.createButton({
		title: 'Switch back to view1'
	});
	btn2.addEventListener('click', function() {
		var view1 = createView1();
		view2.animate({view: view1, transition: Ti.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT});
	});
	view2.add(btn2);
	
	return view2;	
}

var view1 = createView1();
var win = Ti.UI.createWindow();
win.add(view1);
win.open();

Notes

The code sample above is re-creating the views all the times, as - according to the documentation - the view gets destroyed once the animation is over. In fact, if the views are not re-created, the app will crash trying to switch back.

Comments

  1. Vishal Duggal 2013-09-23

    Transition animation on views are to transition subviews of a View (In this case the window). Use this code instead
       function createView1() {
           var view1 = Ti.UI.createView({backgroundColor:'red'});
            
           var btn1 = Ti.UI.createButton({
               title: 'Switch to view2'
           });
           btn1.addEventListener('click', function() {
               win.animate({view: view2, transition: Ti.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT});
           });
           view1.add(btn1);
            
           return view1; 
       }
        
       function createView2() {
           var view2 = Ti.UI.createView();
            
           var btn2 = Ti.UI.createButton({
               title: 'Switch back to view1'
           });
           btn2.addEventListener('click', function() {
               win.animate({view: view1, transition: Ti.UI.iPhone.AnimationStyle.FLIP_FROM_LEFT});
           });
           view2.add(btn2);
            
           return view2;   
       }
        
       var view1 = createView1();
       var view2 = createView2();
       var win = Ti.UI.createWindow();
       win.add(view1);
       win.open();
       
  2. Lee Morris 2017-03-22

    Closing ticket as invalid with reference to the above comments.

JSON Source