So basically I have this app up and running. It's a very basic easy app a ball bounces around the screen and I have a "Start" and "Stop" switch. The "Start" plays an animation of images really quickly. "Stop" stops it.
What I am trying to figure out is how to connect the UIImage movement to the "Start" switch.
So basically I have this app up and running. It's a very basic easy app a ball bounces around the screen and I have a "Start" and "Stop" switch. The "Start" plays an animation of images really quickly. "Stop" stops it.
What I am trying to figure out is how to connect the UIImage movement to the "Start" switch.
I have been trying to come up with an If statement but everything I try keeps coming up with errors, I don't think it's organized correctly.
You have written IBAction methods that start and stop the animation. Those should work perfectly attached to the "touch up inside" event on a pair of buttons.
Are you saying that you want a single switch that turns on the animation if it is in the on position and off if it is in the "off" position?
In that case, you'd write an IBAction like this:
Code:
- (IBAction) switchValueHasChanged: (id) sender;
{
UISwitch* theSwitch = (UISwitch*) sender;
if (theSwitch.on)
{
[self play]; //Call the method you already wrote
}
else
{
[self stop]; //Call the stop method you already wrote.
}
}
Attach the switchValueHasChanged IBAction to the valueChanged event for the switch. Done.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Now when I run app, the image is frozen where I placed it in the storyboard. and when I hit start it starts moving along with the back ground animations.
But I am now trying to figure out the values to change for the -IBAction Stop
You have written IBAction methods that start and stop the animation. Those should work perfectly attached to the "touch up inside" event on a pair of buttons.
Are you saying that you want a single switch that turns on the animation if it is in the on position and off if it is in the "off" position?
In that case, you'd write an IBAction like this:
Code:
- (IBAction) switchValueHasChanged: (id) sender;
{
UISwitch* theSwitch = (UISwitch*) sender;
if (theSwitch.on)
{
[self play]; //Call the method you already wrote
}
else
{
[self stop]; //Call the stop method you already wrote.
}
}
Attach the switchValueHasChanged IBAction to the valueChanged event for the switch. Done.
It's not a switch button. But a round rect button.
I have it linked up. I think I got it.
Now when I run app, the image is frozen where I placed it in the storyboard. and when I hit start it starts moving along with the back ground animations.
But I am now trying to figure out the values to change for the -IBAction Stop
If I put the selector as "nil" it will give me SIGBRT error.
Now when I run app, the image is frozen where I placed it in the storyboard. and when I hit start it starts moving along with the back ground animations.
But I am now trying to figure out the values to change for the -IBAction Stop
Use 2 buttons, a stop button and a start button. Attach each one to it's action, and you're done.
Are you saying that you want a single button that toggles back and forth from a start button to a stop button?
If so, set up a BOOL instance variable animationIsPlaying.
Write a single IBAction method like the one I suggested, only instead of checking the state of a switch, have your action method toggle the state of the animationIsPlaying flag, and then call a method that:
Sets the button title to "start" or "stop" as appropriate based on the flag
Calls the animation stop or start method, as appropriate.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
Use 2 buttons, a stop button and a start button. Attach each one to it's action, and you're done.
Are you saying that you want a single button that toggles back and forth from a start button to a stop button?
If so, set up a BOOL instance variable animationIsPlaying.
Write a single IBAction method like the one I suggested, only instead of checking the state of a switch, have your action method toggle the state of the animationIsPlaying flag, and then call a method that:
Sets the button title to "start" or "stop" as appropriate based on the flag
Calls the animation stop or start method, as appropriate.
I have two buttons a start and a stop. Each button starts and stops the background animation. The ball starts with the start button as well by coding.
But it doesn't stop with the stop button because I don't know what variables to change in the
I have two buttons a start and a stop. Each button starts and stops the background animation. The ball starts with the start button as well by coding.
But it doesn't stop with the stop button because I don't know what variables to change in the
Background animation? Timer? You need to provide a complete, coherent description of what you are trying to do if you want help figuring out. Thus far your descriptions have been neither.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.