UIView animation not performing immediately after the first run. - ios

So basically I have two methods that I run when the user clicks an Annotation in the map.
- (void) methodA{
[UIView animateWithDuration:kRequestButtonAnimationDuration animations:^(void){
self.button.transform = CGAffineTransformMakeTranslation(0,-(self.navigationController.view.frame.size.height - self.button.frame.origin.y)); }]; }
- (void) methodB:(double)value andBoolean:(BOOL) boolean{
if (self.timer) {
[self.timer invalidate];
self.timer = nil;
}
if (boolean) {
self.timer = [NSTimer scheduledTimerWithTimeInterval:value target:self selector:#selector(pullButtonUp) userInfo:nil repeats:NO];
} else{
self.timer = [NSTimer scheduledTimerWithTimeInterval:value target:self selector:#selector(showTabBar) userInfo:nil repeats:NO];
}}
-(void)pullButtonUp{
[(LLTabBarViewController*)self.tabBarController showTabBarAnimated];}
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
[self methodA];
[self methodB:2.0 andBoolean:TRUE];
}
So during the first time I select an annotation, it works well: it runs methodA, then methodB after 2.0 seconds.
But when I try it again, it runs both A and B at the same time (basically methodA waits 2.0 seconds to execute).
Could this be related to Loops?
How should I track this problem? Any instrument? Which one?
I am a bit lost, help me please!

I think this is what you want to do
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
__weak typeof(self) weakSelf = self;
BOOL arbitraryBool = YES;
[UIView animateWithDuration:2
animations:^{
self.button.transform = CGAffineTransformMakeTranslation(0,-(self.navigationController.view.frame.size.height - self.button.frame.origin.y));
} completion:^(BOOL finished) {
if (finished) {
if (arbitraryBool) {
[weakSelf pullButtonUp];
} else {
[weakSelf showTabBar];
}
}
}]:
}

Related

UIPageViewController scroll automatically issue

I have implemented automatic scrolling of UIPageViewController after every 5 seconds using timer like this:
_bannerTimer = [NSTimer scheduledTimerWithTimeInterval:5.0
target:self
selector:#selector(loadNextController)
userInfo:nil
repeats:YES];
- (void)loadNextController
{
self.index++;
HeaderAdVC *nextViewController;
if(self.index>arrayImages.count-1)
{
self.index=0;
[pageIndicator setCurrentPage:0];
nextViewController = [self viewControllerAtIndex:0];
}
else
{
nextViewController = [self viewControllerAtIndex:self.index];
}
[pageIndicator setCurrentPage:self.index];
[pageController setViewControllers:#[nextViewController]
direction:UIPageViewControllerNavigationDirectionForward
animated:YES
completion:nil];
}
and removing the timer in viewWillDisappear
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[_bannerTimer invalidate];
}
Problem :
My problem is when the loadNextController method is called my app stop responding.
If i switch to next page still getting the same problem on every view.
Do some changes like below , do all non-ui task in background thread and all UI operation in Main thread ,try this
- (void)loadNextController
{
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
self.index++;
HeaderAdVC *nextViewController;
if(self.index>arrayImages.count-1)
{
self.index=0;
[pageIndicator setCurrentPage:0];
nextViewController = [self viewControllerAtIndex:0];
}
else
{
nextViewController = [self viewControllerAtIndex:self.index];
}
dispatch_async(dispatch_get_main_queue(), ^{
[pageIndicator setCurrentPage:self.index];
[pageController setViewControllers:#[nextViewController]
direction:UIPageViewControllerNavigationDirectionForward
animated:YES
completion:nil];
});
});
}
i hope this will help you ..

Xcode Disposing memory - images taking up too much memory and won't deallocate

Updated:
I have a lot of view controllers and the app is image heavy. Each is presented modally at the moment. I'm disposing of all my images,timers etc and whatever else in viewwilldisappear on every view controller, but when it segues it just seems to be allocating memory continually on top of the previous VC and everything else without getting rid of a single thing which eventually crashes it (i know this will happen with modal segues).
How can i change this? I have tried embedding my controllers in a navigation controller but the same problem is still happening where it will not release any of the images on the controllers. Here is an example of my code and where i'm getting rid of what i've created in VWD. VWD is definitely being called. Hopefully this makes sense to someone, thanks in advance.
#interface AnimationStartViewController ()
#end
#implementation AnimationStartViewController
SystemSoundID skipintro;
-(void) viewDidLoad
{
[super viewDidLoad];
(sleep(2.5));
NSString *music=[[NSBundle mainBundle]pathForResource:#"1Animation" ofType:#"mp3"];
animationaudio=[[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL fileURLWithPath:music] error:NULL];
animationaudio.delegate= (id)self;
animationaudio.numberOfLoops=-1;
[animationaudio play];
NSURL *skipintroURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"Click" ofType:#"mp3"]];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)skipintroURL, &skipintro);
//Text Timers
text1timer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:#selector(Text1show:) userInfo:nil repeats:NO];
text2timer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:#selector(Text2show:) userInfo:nil repeats:NO];
text3timer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:#selector(Text3show:) userInfo:nil repeats:NO];
text4timer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:#selector(Text4show:) userInfo:nil repeats:NO];
text5timer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:#selector(Text5show:) userInfo:nil repeats:NO];
text6timer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:#selector(Text6show:) userInfo:nil repeats:NO];
text7timer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:#selector(Text7show:) userInfo:nil repeats:NO];
text8timer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:#selector(Text8show:) userInfo:nil repeats:NO];
logotimer = [NSTimer scheduledTimerWithTimeInterval:0.0 target:self selector:#selector(showlogo) userInfo:nil repeats:NO];
pushtimer = [NSTimer scheduledTimerWithTimeInterval:20.0 target:self selector:#selector(performthesegue) userInfo:nil repeats:NO];
//Text Timers invalidate
stoptext1timer = [NSTimer scheduledTimerWithTimeInterval:6.0 target:self selector:#selector(invalidatetext1) userInfo:nil repeats:NO];
stoptext2timer = [NSTimer scheduledTimerWithTimeInterval:6.0 target:self selector:#selector(invalidatetext2) userInfo:nil repeats:NO];
stoptext3timer = [NSTimer scheduledTimerWithTimeInterval:6.0 target:self selector:#selector(invalidatetext3) userInfo:nil repeats:NO];
stoptext4timer = [NSTimer scheduledTimerWithTimeInterval:6.0 target:self selector:#selector(invalidatetext4) userInfo:nil repeats:NO];
stoptext5timer = [NSTimer scheduledTimerWithTimeInterval:14.5 target:self selector:#selector(invalidatetext5) userInfo:nil repeats:NO];
stoptext6timer = [NSTimer scheduledTimerWithTimeInterval:14.5 target:self selector:#selector(invalidatetext6) userInfo:nil repeats:NO];
stoptext7timer = [NSTimer scheduledTimerWithTimeInterval:14.5 target:self selector:#selector(invalidatetext7) userInfo:nil repeats:NO];
stoptext8timer = [NSTimer scheduledTimerWithTimeInterval:14.5 target:self selector:#selector(invalidatetext8) userInfo:nil repeats:NO];
moveAnimationTimer = [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:#selector(moveAnimation) userInfo:nil repeats:YES];
stopAnimationTimer = [NSTimer scheduledTimerWithTimeInterval:20.0 target:self selector:#selector(StopAnimation) userInfo:nil repeats:NO];
}
//scrolling Animation.
- (void) moveAnimation {
animation.center = CGPointMake(animation.center.x, animation.center.y -2);
}
//Stop
- (void) StopAnimation {
[moveAnimationTimer invalidate];
moveAnimationTimer = nil;
}
//====================== Text animations
//AttheGateof
-(void)Text1show:(NSTimer *)timer {
[UIView animateWithDuration:2.0 delay:0.70
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^ {
Atthegateof.alpha = 1.0f;
}
completion:^(BOOL finished) {
Atthegateof.alpha = 1.0f;
}];
}
//MidnightZoo
-(void)Text2show:(NSTimer *)timer {
[UIView animateWithDuration:2.0 delay:1.75
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
MidnightZoo.alpha = 1.0f;
}
completion:^(BOOL finished) {
MidnightZoo.alpha = 1.0f;
}];
}
//Who lives inside
-(void)Text3show:(NSTimer *)timer {
[UIView animateWithDuration:2.0 delay:2.9
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
Wholivesinside.alpha = 1.0f;
}
completion:^(BOOL finished) {
}];
}
// Thedeepblackblue
-(void)Text4show:(NSTimer *)timer {
[UIView animateWithDuration:2.0 delay:3.3
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
Thedeepblackblue.alpha = 1.0f;
}
completion:^(BOOL finished) {
}];
}
//unlockthegate
-(void)Text5show:(NSTimer *)timer {
[UIView animateWithDuration:2 delay:7
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
Unlockthegate.alpha = 1.0f;
}
completion:^(BOOL finished) {
}];
}
//tocomeinside
-(void)Text6show:(NSTimer *)timer {
//music 'high' point
[UIView animateWithDuration:2 delay:7.5
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
Tocomeinside.alpha = 1.0f;
}
completion:^(BOOL finished) {
}];
}
//behindeachlock
-(void)Text7show:(NSTimer *)timer {
[UIView animateWithDuration:2 delay:8.2
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
Behindeachlock.alpha = 1.0f;
}
completion:^(BOOL finished) {
}];
}
//something hides
-(void)Text8show:(NSTimer *)timer {
[UIView animateWithDuration:2 delay:8.7
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
Somethinghides.alpha = 1.0f;
}
completion:^(BOOL finished) {
}];
}
//======================================= Get rid of text
//indvalidate 1
-(void)invalidatetext1 {
[stoptext1timer invalidate];
stoptext1timer = nil;
[UIView animateWithDuration:0.7 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
Atthegateof.alpha = 0;
} completion:^(BOOL finished) {
[Atthegateof removeFromSuperview];
} ];
}
//invalidate 2
-(void)invalidatetext2 {
[stoptext2timer invalidate];
stoptext2timer = nil;
[UIView animateWithDuration:0.7 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
MidnightZoo.alpha = 0;
} completion:^(BOOL finished) {
[MidnightZoo removeFromSuperview];
} ];
}
//invalidate 3
-(void)invalidatetext3 {
[stoptext3timer invalidate];
stoptext3timer = nil;
[UIView animateWithDuration:0.7 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
Wholivesinside.alpha = 0;
} completion:^(BOOL finished) {
[Wholivesinside removeFromSuperview];
} ];
}
//invalidate 4
-(void)invalidatetext4 {
[stoptext4timer invalidate];
stoptext4timer = nil;
[UIView animateWithDuration:0.7 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
Thedeepblackblue.alpha = 0;
} completion:^(BOOL finished) {
[Thedeepblackblue removeFromSuperview];
} ];
}
//invalidate 5
-(void)invalidatetext5 {
[stoptext5timer invalidate];
stoptext5timer = nil;
[UIView animateWithDuration:0.75 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
Unlockthegate.alpha = 0;
} completion:^(BOOL finished) {
[Unlockthegate removeFromSuperview];
} ];
}
//invalidate 6
-(void)invalidatetext6 {
[stoptext6timer invalidate];
stoptext6timer = nil;
[UIView animateWithDuration:0.75 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
Tocomeinside.alpha = 0;
} completion:^(BOOL finished) {
[Tocomeinside removeFromSuperview];
} ];
}
//invalidate 7
-(void)invalidatetext7 {
[stoptext7timer invalidate];
stoptext7timer = nil;
[UIView animateWithDuration:0.75 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
Behindeachlock.alpha = 0;
} completion:^(BOOL finished) {
[Behindeachlock removeFromSuperview];
} ];
}
//invalidate 8
-(void)invalidatetext8 {
[stoptext8timer invalidate];
stoptext8timer = nil;
[UIView animateWithDuration:0.75 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
Somethinghides.alpha = 0;
} completion:^(BOOL finished) {
[Somethinghides removeFromSuperview];
} ];
}
//=======================================
-(void)showlogo {
[UIView animateWithDuration:2.0 delay:16.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
zoowhologo.alpha = 1.0f;
}
completion:^(BOOL finished) {
zoowhologo.alpha = 1.0f;
}];
}
-(void)performthesegue {
[self performSegueWithIdentifier:#"pushgototitle" sender:nil];
}
- (void)didReceiveMemoryWarning
{
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
NSLog(#"viewilldisappear was called");
[animationaudio stop];
[text1timer invalidate], text1timer=nil;
[text2timer invalidate], text2timer=nil;
[text3timer invalidate], text3timer=nil;
[text4timer invalidate], text4timer=nil;
[text5timer invalidate], text5timer=nil;
[text6timer invalidate], text6timer=nil;
[text7timer invalidate], text7timer=nil;
[text8timer invalidate], text8timer=nil;
[stoptext1timer invalidate], stoptext1timer=nil;
[stoptext2timer invalidate], stoptext2timer=nil;
[stoptext3timer invalidate], stoptext3timer=nil;
[stoptext4timer invalidate], stoptext4timer=nil;
[stoptext5timer invalidate], stoptext5timer=nil;
[stoptext6timer invalidate], stoptext6timer=nil;
[stoptext7timer invalidate], stoptext7timer=nil;
[stoptext8timer invalidate], stoptext8timer=nil;
[logotimer invalidate], logotimer=nil;
[pushtimer invalidate], pushtimer=nil;
[moveAnimationTimer invalidate], moveAnimationTimer=nil,
[stopAnimationTimer invalidate], stopAnimationTimer=nil;
AudioServicesDisposeSystemSoundID(skipintro);
[Atthegateof removeFromSuperview], Atthegateof=nil;
[MidnightZoo removeFromSuperview], MidnightZoo=nil;
[Wholivesinside removeFromSuperview], Wholivesinside=nil;
[Thedeepblackblue removeFromSuperview], Thedeepblackblue=nil;
[Unlockthegate removeFromSuperview], Unlockthegate=nil;
[Tocomeinside removeFromSuperview], Tocomeinside=nil;
[Behindeachlock removeFromSuperview], Behindeachlock=nil;
[Somethinghides removeFromSuperview], Somethinghides=nil;
[topper removeFromSuperview], topper=nil;
[skip removeFromSuperview], skip=nil;
[zoowhologo removeFromSuperview], zoowhologo=nil;
[animation removeFromSuperview], animation = nil;
[stopanimation removeFromSuperview], stopanimation = nil;
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)skipintro:(id)sender {
AudioServicesPlaySystemSound(skipintro);
[animationaudio stop];
[pushtimer invalidate];
[self performSegueWithIdentifier:#"pushgototitle2" sender:self];
[self.presentingViewController dismissViewControllerAnimated:NO completion:nil];
}
Several things.
If you present view controllers modally, they get stacked up one on top of the next, and none of them get released until you dismiss them. Make sure you're not creating a new instance of a previous view controller and pushing it modally instead of dismissing back to the desired VC.
Second,
It used to be that when a view controller was moved off-screen, it's view hierarchy was unloaded, freeing up most of the memory it took. That's no longer true. (and hasn't been for quite a few major iOS releases. I want to say this changed in iOS 4, but am not positive of this.)
If a view controller is in memory, so is it's entire view hierarchy, including any images that are installed in image views inside those views.
You can indeed implement a viewWillDisappear method and use that method to nil out any data structures that are not installed in your view hierarchy. You then need to implement a viewWillAppear method that reloads those data structures.
If your app presents a series of view controllers modally, and then the user "unrolls" each view controller and returns back to the root view controller then your method of using modal presentation is reasonable. (Using a navigation controller and a stack of pushed view controllers might be better, but you claim not.) Both approaches keep a stack of all the previously visited view controllers active and in memory.
If instead your UX has your user move from VC to VC without the need to return, you should instead implement your own custom segue that dismisses the previous view controller, or perhaps uses a child view controller that it swaps for another one as the user navigates.

How to create auto scrolling UITextView in the Xcode

I try to create a UITexView with auto scrolling when press button start. And have a button stop, when pressed it will stop scrolling. Pressing button start again and it will continues to scroll down. How to handle this function.
I have research some code that this code below work with me.
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSLog(#"%f %f",_txvSentence.contentSize.width , _txvSentence.contentSize.height);
if (scrollingTimer == nil) {
scrollingTimer = [NSTimer scheduledTimerWithTimeInterval:(35.0/1000.0)
target:self
selector:#selector(autoscrollTimerFired:)
userInfo:nil
repeats:YES];
NSLog(#"%#",scrollingTimer);
}
}
- (void)autoscrollTimerFired:(NSTimer*)timer {
CGPoint scrollPoint = self.txvSentence.contentOffset;
//scrollPoint = CGPointMake(scrollPoint.x, scrollPoint.y + 1);
scrollPoint = _txvSentence.contentOffset;
scrollPoint.y= scrollPoint.y+1;
[_txvSentence setContentOffset:scrollPoint animated:NO];
//[self.txvSentence setContentOffset:scrollPoint animated:NO];
}
But i cannot stop this animation. And how to set dynamic duration such as when come to the end of text it automatically stop.
Sorry because my bad english. If not understand please tell me where I will explain it clearly.
Try this:
self.scrollView.scrollEnabled = NO;
CGFloat scrollHeight = 100;
//===
- (void) spinWithOptions: (UIViewAnimationOptions) options {
// this spin completes 360 degrees every 2 seconds
[UIView animateWithDuration:10
delay:0
options:options
animations:^{
self.scrollView.contentOffset = CGPointMake(0, scrollHeight);
}
completion:^(BOOL finished) {
if (finished) {
if (animating) {
// if flag still set, keep spinning with constant speed
[self spinWithOptions: UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction];
} else if (options != UIViewAnimationOptionCurveEaseOut) {
// one last spin, with deceleration
[self spinWithOptions: UIViewAnimationOptionCurveEaseOut];
}
}
}];
}
- (void) startAnimating {
if (!animating) {
animating = YES;
[self spinWithOptions: UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction];
}
}
- (void) stopAnimating {
// set the flag to stop spinning after one last 90 degree increment
animating = NO;
}
You can use NSTimer.
// Global var
CGFloat scrollHeight = MAX_HEIGHT;
CGFloat currentOffsetY = 0.0f;
NSTimer *timer;
self.timer = [NSTimer scheduledTimerWithTimeInterval:YOUR_TIME_INTERVAL target:self selector:#selector(scrollText:) userInfo:nil repeats:YES];
- (void)scrollText:(NSTimer *)timer {
currentOffsetY++;
if (currentOffsetY >= MAX_HEIGHT) {
[self.timer invalide];
}
self.scrollView.contentOffset = CGPointMake(0, currentOffsetY);
}
// Your button action
- (void)stopAnimation:(UIButton *)button {
[self.timer invalide];
}

progress bar showing tick animation instead of smooth animation when used with NSTimer

I am using NSTimer and circular progress bar for the countdown timer i.e 15seconds
Its working with the following code but I am getting tick animation for the progress bar and not the smooth one, how to make it smooth animation
- (void)viewDidLoad
{
[super viewDidLoad];
self.labeledLargeProgressView.roundedCorners = NO;
self.labeledLargeProgressView.trackTintColor =[UIColor colorWithRed:0.0f/255.0f green:173.0f/255.0f blue:255.0f/255.0f alpha:1.0f];
self.labeledLargeProgressView.progressTintColor =[UIColor colorWithRed:255.0f/255.0f green:96.0f/255.0f blue:88.0f/255.0f alpha:1.0f];
self.labeledLargeProgressView.thicknessRatio = 1.0f;
self.labeledLargeProgressView.clockwiseProgress = YES;
[self.view addSubview:self.labeledLargeProgressView];
seconds = 15.0;
[self startAnimation];
}
- (void)progressChange
{
CGFloat progress ;
DALabeledCircularProgressView *labeledProgressView = self.labeledLargeProgressView;
if(labeledProgressView.progress >=1.0f && [self.timer isValid]){
[self stopAnimation];
seconds = 15.0f;
}
else{
progress=labeledProgressView.progress + 0.06666667f;
[labeledProgressView setProgress:progress animated:YES];
seconds --;
labeledProgressView.progressLabel.text = [NSString stringWithFormat:#"%i", seconds];
}
}
- (void)startAnimation
{
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:#selector(progressChange)
userInfo:nil
repeats:YES];
self.continuousSwitch.on = YES;
}
- (void)stopAnimation
{
[self.timer invalidate];
self.timer = nil;
self.continuousSwitch.on = NO;
}
What i found out is a set of both UIview animations and progress view animatons that work much nicer and animate the progressview smoothly. If you just use the combination of animation and progressview animation it is fired directly without regard to the UIview animation timer.
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
timer = [NSTimer scheduledTimerWithTimeInterval: 1.0f
target: self
selector: #selector(updateTimer)
userInfo: nil
repeats: YES];
}
- (void)updateTimer
{
if (progressView.progress >= 1.0) {
[timer invalidate];
}
[UIView animateWithDuration:1 animations:^{
float newProgress = [self.progressView progress] + 0.125;
[self.progressView setProgress:newProgress animated:YES];
}];
}
Feel free to adjust the animation times to even better and smooth transitions
I solved it by myself what I did is I am updating more frequently 0.1f instead of 1.0f
- (void)progressChange
{
CGFloat progress ;
DALabeledCircularProgressView *labeledProgressView = self.labeledLargeProgressView;
if(labeledProgressView.progress >=1.0f && [self.timer isValid]){
[self stopAnimation];
seconds = 15.0f;
_counter = 0;
}
else{
progress=labeledProgressView.progress + 0.00666667f;
_counter ++;
[labeledProgressView setProgress:progress animated:YES];
if(_counter % 10 == 0){
seconds --;
}
labeledProgressView.progressLabel.text = [NSString stringWithFormat:#"%i", seconds];
}
}
- (void)startAnimation
{
self.timer = [NSTimer scheduledTimerWithTimeInterval:0.1
target:self
selector:#selector(progressChange)
userInfo:nil
repeats:YES];
self.continuousSwitch.on = YES;
}

animation not firing

I have a simple explosion animation that works just fine in any method in my class. However I want to call it once the timer runs out, from the timer update method. The problem is it will not work from here for whatever reason (something to do with the timer surely). It simply unhides my image.. no animation. I cannot figure out how to get it to work.
- (void)explosionAnimation
{
imgExplosion.hidden=FALSE;
//set starting point of explosion
CGRect explosionFrame = self.imgExplosion.frame;
explosionFrame.origin.x = explosionFrame.origin.y = -960.0f;
explosionFrame.size.width = explosionFrame.size.height = 1920.0f;
[UIView animateWithDuration:1.5f animations:^{
self.imgExplosion.frame = explosionFrame;
} completion:^(BOOL finished) {
self.imgExplosion.hidden = YES;
}];
}
-(void) createTimer
{
// Create timer instance
if (timer != nil){
[timer invalidate];
hasTimerStarted = NO;
}
// Initialize the timer.
timer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:#selector(timerUpdater)
userInfo:nil repeats:YES];
}
- (void)timerUpdater{
if(!hasTimerStarted){
intTotalSeconds = [strTotalNumberofSeconds intValue];
hasTimerStarted = YES;
}
else{
intTotalSeconds--;
self.lblTimer.text = [self revertTimeToString:intTotalSeconds];
}
// if totalSeconds hits zero, then time is up! You lose!
if (intTotalSeconds == 0){
[timer invalidate];
[self explosionAnimation];
hasTimerStarted = NO;
[self addPlayAgainButton];
}
}
Try putting some delay or call explosion method on Main Thread like
[self performSelector:#Selector(explosionAnimation) withObject:nil afterDelay:1.0];

Resources