Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

JGoose

macrumors member
Original poster
Feb 12, 2010
41
0
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.
 
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?
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.
 
You know it was wrong like that earlier, but I already changed it and it didn't help.
 
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?
 
Try Clean All Targets under the Build menu. Might need to exit and restart Xcode if it's grayed out.


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

And you're sure you've copied the image into your application bundle (not just referencing it)?

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

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?

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.
 
I tried that, but it didn't help. What exactly does this do?

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.
 
Try Clean All Targets under the Build menu. Might need to exit and restart Xcode if it's grayed out.

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.
 
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.
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.

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.
"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.
 
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.

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.
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.