I have an app I'm creating and I need some help. Under the view did load I have a code to play music which is fine. Then there is button saying 'play' when they click play the music STOPS and a animation starts. Now after the animation finished 2 buttons appear. How would I state animation stop animating like a void or ibaction so then I can put when the animation stop animating happens play the music again. If this dosent make sense please feel free to ask questions, Im a beginner so take it easy on me :) thanks
+ (void)animateWithDuration:(NSTimeInterval)duration
animations:(void (^)(void))animations
completion:(void (^)(BOOL finished))completion
Would allow you to know when an animation is completed, code in the completion block will be executed when the animation finishes.
Related
I was wondering, what if I want to replay an animation I have already added to the layer? Do I need to add the animation to the layer each and every time I want it to play, or there's a way to replay an animation I have already added?
Thanks,
iLyrical.
Once animation gets finished then to repeat animation u will have to add new animation like this:
[yourView.layer removeAllAnimations];
[yourView.layer addAnimation:yourAnimation forKey:#"Key here"];
You can configure the animation to repeat a certain number of times before it finishes using the repeatCount property but if you want to repeat an animation that has already finished you have to add it to the layer again.
In the MainViewController, I have a play/pause button. I was having problem in coding for the pause function because when i was using audio player pause it was pausing only the audio player but in background my application was still executing. I have used NSTimer for displaying various UIViewControllers. While audio player is paused it is still displaying UIViewControllers because of NSTimer.Whereas i wanted complete pause audio player & application execution as well at the same time.
I found this -applicationwillresignactive. Do you think this -applicationwillresignactive can help me when i want complete pause audio player plus application pause.
Please suggest.
applicationWillResignActive and applicationDidEnterBackground are called when home button is pressed.
I have a toggle menu which toggle between the words "Pause" and "Resume" when it is pressed, which also pause and resume the whole game. This means when playing, the menu will be shown as "Pause" (tap here to pause), when pausing the menu will be shown as "Resume" (tap here to resume).
Here is the problem, if I tap the home button after I pause the game, then go back into it, it resumes itself and the pause menu is shown as "Resume". And this doesn't make sense to me. The best way I want is to pause the game whenever go into the background and resume from background. I look at the following methods, but they don't really work:
-(void)applicationWillResignActive:(UIApplication *)application{
}
- (void)applicationDidBecomeActive:(UIApplication *)application{
}
-(void)applicationWillEnterBackground:(UIApplication*)application{
}
-(void)applicationDidEnterBackground:(UIApplication *)application {
}
I even just put CCLOG in all of those methods, but nothing has been called. Is there something I am need to put/declare before I use those methods?
Sorry, it is a bit too long to read. Hope you can help me. Thank you.
I'm not sure why, but for my experience (not cocos2d), there's no additional implementation if want apply those methods.
perhaps, you should try look at this.
link 1 & link 2
-(void)applicationWillResignActive:(UIApplication *)application{
}
- (void)applicationDidBecomeActive:(UIApplication *)application{
}
you need custom your cocos2d CCDIRECTOR class. And get now display layer. then active it pause or resume function. All this must need some protocol.
These methods are invoked when the iOS forces your application in the background, or resumes execution of your application, ie they are signals you receive when an external event causes your application to go to background, or come back from it. You should not try to invoke them directly. There is no real relationship with a 'user created' menu like yours (like your Resume/Pause menu), unless you make the relationship explicit.
So , in the following method:
- (void)applicationWillResignActive:(UIApplication *)application {
NSLog(#"<%#>:applicationWillResignActive - received signal, pausing sharedDirector.",[self class]);
// here : place your code for forcing your menu in the 'Resume' state
// i am assuming some kind of change in a button, and
// a state variable of your own that define and control
// what it means to be 'paused' from your applications point of
// view
// then force the director to pause (animations, scheduling, touch, etc ...)
[[CCDirector sharedDirector] pause];
}
after, when the iOS hands you back control by placing your application in the forground as the running application:
- (void)applicationDidBecomeActive:(UIApplication *)application {
NSLog(#"<%#>:applicationDidBecomeActive - received signal, resuming sharedDirector.",[self class]);
[[CCDirector sharedDirector] resume];
}
You dont really need to do anything fancy here other than restart the CCDirector, since your menu is in the 'Resume' state, garanteed. When user presses Resume, you will start your game again and put the menu in the 'Pause' state.
In my viewWillAppear:(bool)animated method I want to stop video playing. How can I do this? I am new I don't know much.
I am playing a video on this screen. I have a tab which shows table view. When I click on the tab the table view is shown but video is playing in background: we can hear the music.
If you are using MPMoviePlayerController, call -pause on that object.
I have an app with a splash screen. For the splashscreen I've decided to add a m4v movie. I'm using the MPMoviePlayerController to show the movie. Everything is working as expected except for one thing:
I'm trying to make the MPMoviePlayerController loop by subscribing to it's MPMoviePlayerPlaybackDidFinishNotification notification and issuing a [notification.object play] if the data didn't finish loading.
This works partially, it restarts the movie, but there's the fadeout and re-fadein that make it look bad.
Is there any other way to loop the movie?
Or any way to remove the fades?
Try this single line of code:
myPlayer.repeatMode = MPMovieRepeatModeOne;
:)
By complete coincidence I have just written a blog post on this subject - we ran into this problem while we were writing our latest app :)
Assuming that you don't want to follow my shameless plug, here's how we fixed it :
Make sure that the movie starts
and ends on the same frame.
Make the starting frame the Default.png of the app
On startup add Default.png to the window as a UIImageView
Make the movie have a clear background
Play and loop the movie
When the movie ends, it will fade out before it loops round. As Default.png is exactly the same as the start and end frames, the user will never notice :)
When you want to end the movie just remove the Default.png UIImageView and stop the movie - as the background is clear it will just fade out to whatever ui you have in your window.
Sam
I don't think there is any public option to do this. You could try and inspect Erica Sadun's Class Dumps for a method you can override that would handle the fading. Maybe a videoDidFinish method or something.
Have you tried messing around with the backgroundColor property? Apple's MPMoviePlayerController docs say
"The receiver fades to and from the
background color when transitioning to
and from playback...The default color
for this property is black. You can
change this to other colors (including
clear) to provide a more appropriate
transition from your application’s
content to the movie content."
So, you can probably try setting it to [UIColor clearColor] and seeing if that helps.