Animation works on Simulator, but not on Ipod

Discussion in 'iOS Programming' started by JGoose, Apr 12, 2010.

  1. JGoose macrumors member

    Joined:
    Feb 12, 2010
    #1
    I have the following code in my app. This is connected to a slider for choosing a level to play. An image of the selected level flashes on the screen. It all works perfectly when trying it in the simulator, but when I try it on my Ipod all levels work except level one. I thought maybe I mistyped @"levelOneImage.png"

    But I didn't because it DOES work in the simulator. Does anyone know what could be causing this not to work on the Ipod?

    Code:
    if (level == 1) 
    	{
    		[levelView setImage: [UIImage imageNamed: @"levelOneImage.png"]];
    		
    		[UIView beginAnimations: @"levelOneAnimation" context: nil];
    		[UIView setAnimationDuration: 1.0];
    		[levelView setAlpha: 1.0];
    		[levelView setAlpha: 0.0];
    		
    		[UIView commitAnimations];
    	}
    	else if (level == 2)
    	{
    		[levelView setImage: [UIImage imageNamed: @"levelTwoImage.png"]];
    		
    		[UIView beginAnimations: @"levelTwoAnimation" context: nil];
    		[UIView setAnimationDuration: 1.0];
    		[levelView setAlpha: 1.0];
    		[levelView setAlpha: 0.0];
    		
    		[UIView commitAnimations];
    	}
    
    what stumps me is that all the animations are identical except for the images of course.
     
  2. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Might be because the Simulator is case-insensitive whereas running on the actual device is case-sensitive. Make sure you have the case in the code and the case of the actual file name in the bundle matching exactly.
     
  3. JGoose thread starter macrumors member

    Joined:
    Feb 12, 2010
    #3
    You know it was wrong like that earlier, but I already changed it and it didn't help.
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    And you're sure you've copied the image into your application bundle (not just referencing it)?
     
  5. MacToddB macrumors 6502a

    MacToddB

    Joined:
    Aug 21, 2007
    Location:
    Rochester, NY
    #5
    Try Clean All Targets under the Build menu. Might need to exit and restart Xcode if it's grayed out.
     
  6. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #6
    I don't understand why you're setting the alpha twice inside the animation block. I would expect that you would set it once outside and then animate the change by setting it inside the animation block. Am I missing something?
     
  7. JGoose thread starter macrumors member

    Joined:
    Feb 12, 2010
    #7

    I tried that, but it didn't help. What exactly does this do?

    Yes, I put it into the app along with all the others that are working.

    Before this method is called the alpha is set to 0.0 so what this animation does is make the image appear then fade out.
     
  8. MacToddB macrumors 6502a

    MacToddB

    Joined:
    Aug 21, 2007
    Location:
    Rochester, NY
    #8
    If you change an image (or in your case, change the capitalization of an imagefile), the old one might still be there. Cleaning forces it to build the app from scratch.

    Could the animation just be happening to quickly to see? Is there a way to slow it down? Try different fade values, so you can see if it is indeed "trying" to do the animation, i.e. from 1 to 0.5, or from 0.5 to 1, etc.
     
  9. JGoose thread starter macrumors member

    Joined:
    Feb 12, 2010
    #9
    Now I tried just "Clean" instead of "Clean All Targets" and it fixed it. What is the difference between the two. The same alert panel pops up for both.

    Thanks for the help.
     
  10. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #10
    You sure about that? Because setting the alpha to 1.0 and 0.0 inside the animation-block should not be decrementing it as you hope. What you set inside the block are the values you want at the end of the animation, so the 0.0 will just override the 1.0. I think you're getting lucky because your alpha is already at 1.0 before the animation starts. Try removing the setting of it to 1.0 and see if it still works.

    "Clean" just cleans for the current target. I'm surprised that worked and "Clean All Targets" didn't, since the latter is more far-reaching.
     
  11. JGoose thread starter macrumors member

    Joined:
    Feb 12, 2010
    #11
    before this method is called the alpha is always set to 0.0

    what happened here is that it set it to 1.0 instantly (without animation) then faded it to 0.0

    I guess I didn't really do this in the ideal way. the right way is to set the alpha to 1.0 before the animation block. in the end both ways are getting the same effect, but I will change it to make it more readable.
     
  12. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #12
    The correct way is to chain your animation blocks, or maybe you can have them nested, never tried that.

    If you want the alpha to fade between 0 -> 1 -> 0 then you initialize the view with alpha of 0. In the first block you animate it to 1 and then you start another animation block as a termination routine from the first one and animate the alpha back to 0.
     

Share This Page