ios - UIView animations canceling each other -
i have problem when playing multiple uiview animation blocks.
what have game lot of buttons, when press button spawns uilabel animates top of screen gets "added" total point amount, done using 3 nested blocks. works lets me spawn many point labels possible animations on them.
//setup label uilabel *pointindicator = [[uilabel alloc]initwithframe:cgrectmake(button.button.frame.origin.x, button.button.frame.origin.y, 60, 30)]; pointindicator.backgroundcolor = [uicolor clearcolor]; pointindicator.font = [uifont boldsystemfontofsize:25]; pointindicator.alpha = 0; pointindicator.layer.shadowoffset = cgsizemake(1.0f, 1.0f); pointindicator.layer.shadowopacity = 0.6; pointindicator.layer.shadowradius = 1; [pointindicators addobject:pointindicator]; [self.view addsubview:pointindicator]; cgpoint scorelabelposition = [self.view convertpoint:self.totalscorelabel.frame.origin fromview:self.totalscorelabel.superview]; cgsize scorelabelsize = [self.totalscorelabel.text sizewithfont:self.totalscorelabel.font]; [uilabel animatewithduration:0.3 delay:0 options:uiviewanimationcurveeasein animations:^{ //make label appear , move above button cgrect frame = pointindicator.frame; frame.origin.y -= 30; pointindicator.frame = frame; pointindicator.alpha = 1; }completion:^(bool finished){ [uilabel animatewithduration:0.4 delay:0 options:uiviewanimationcurveeaseinout animations:^{ //move label next score label nsinteger yposition = 0; if ([uidevice currentdevice].userinterfaceidiom == uiuserinterfaceidiompad){ yposition = 15; }else{ yposition = 2; } cgrect frame = pointindicator.frame; frame.origin.x = scorelabelposition.x + self.totalscorelabel.frame.size.width/2 + scorelabelsize.width/2 + 5; frame.origin.y = scorelabelposition.y - self.totalscorelabel.frame.size.height/2 + yposition; pointindicator.frame = frame; }completion:^(bool finished){ [uilabel animatewithduration:0.5 animations:^{ pointindicator.alpha = 0; }completion:^(bool finished){ //animate point label increase bit in size cabasicanimation *pointanim = [cabasicanimation animationwithkeypath:@"transform"]; pointanim.timingfunction = [camediatimingfunction functionwithname:kcamediatimingfunctioneaseineaseout]; pointanim.duration = 0.1; pointanim.repeatcount = 1; pointanim.autoreverses = yes; pointanim.removedoncompletion = yes; pointanim.tovalue = [nsvalue valuewithcatransform3d:catransform3dmakescale(1.5, 1.5, 1.0)]; [self.totalscorelabel.layer addanimation:pointanim forkey:nil]; [pointindicator removefromsuperview]; [pointindicators removeobject:pointindicator]; }]; }]; }];
however, when game ended buttons animate out of screen , image view grows in size out of middle, each using 1 animation block.
the problem if uilabel animating across screen @ same time game ends cancels button animation , growing image animation. if no uilabels spawned plays should. tried cancel , remove point labels before playing other animations, no luck. seems work if previous animations have been completed in advance. how remove them:
for(uiview *pointview in pointindicators){ [pointview.layer removeallanimations]; [pointview removefromsuperview]; } [pointindicators removeallobjects]; [self.totalscorelabel.layer removeallanimations];
all views animated subviews of same uiview. noticed if make point labels subviews of buttons animations can play @ same time.
i cant seem figure out behavior, there sort of conflict between animations?
Comments
Post a Comment