CABasicAnimation does not work on the device (iPhone 5s)

I have a CABasicAnimation that creates the effect of cropping the iris in the image. In short, the animation works great on the simulator, but there is no joy on the device. Timers still work correctly and an animation block is activated, but there is no visible animation.

Here is the code to get the iris cleaning job:

- (void)irisWipe { animationCompletionBlock theBlock; _resultsImage.hidden = FALSE;//Show the image view [_resultsImage setImage:[UIImage imageNamed:@"logoNoBoarder"]]; [_resultsImage setBackgroundColor:[UIColor clearColor]]; [_resultsImage setFrame:_imageView.bounds]; //Create a shape layer that we will use as a mask for the waretoLogoLarge image view CAShapeLayer *maskLayer = [CAShapeLayer layer]; CGFloat maskHeight = _resultsImage.layer.bounds.size.height; CGFloat maskWidth = _resultsImage.layer.bounds.size.width; CGPoint centerPoint; centerPoint = CGPointMake( maskWidth/2, maskHeight/2); //Make the radius of our arc large enough to reach into the corners of the image view. CGFloat radius = sqrtf(maskWidth * maskWidth + maskHeight * maskHeight)/2; // CGFloat radius = MIN(maskWidth, maskHeight)/2; //Don't fill the path, but stroke it in black. maskLayer.fillColor = [[UIColor clearColor] CGColor]; maskLayer.strokeColor = [[UIColor blackColor] CGColor]; maskLayer.lineWidth = radius; //Make the line thick enough to completely fill the circle we're drawing // maskLayer.lineWidth = 10; //Make the line thick enough to completely fill the circle we're drawing CGMutablePathRef arcPath = CGPathCreateMutable(); //Move to the starting point of the arc so there is no initial line connecting to the arc CGPathMoveToPoint(arcPath, nil, centerPoint.x, centerPoint.y-radius/2); //Create an arc at 1/2 our circle radius, with a line thickess of the full circle radius CGPathAddArc(arcPath, nil, centerPoint.x, centerPoint.y, radius/2, 3*M_PI/2, -M_PI/2, NO); maskLayer.path = arcPath; //Start with an empty mask path (draw 0% of the arc) maskLayer.strokeEnd = 1.0; CFRelease(arcPath); //Install the mask layer into out image view layer. _resultsImage.layer.mask = maskLayer; //Set our mask layer frame to the parent layer bounds. _resultsImage.layer.mask.frame = _resultsImage.layer.bounds; //Create an animation that increases the stroke length to 1, then reverses it back to zero. CABasicAnimation *swipe = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; swipe.duration = 1; swipe.delegate = self; [swipe setValue: theBlock forKey: kAnimationCompletionBlock]; swipe.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; swipe.fillMode = kCAFillModeForwards; swipe.removedOnCompletion = NO; swipe.autoreverses = NO; swipe.toValue = [NSNumber numberWithFloat: 0]; //Set up a completion block that will be called once the animation is completed. theBlock = ^void(void) { NSLog(@"completed"); }; [swipe setValue: theBlock forKey: kAnimationCompletionBlock]; // doingMaskAnimation = TRUE; [maskLayer addAnimation: swipe forKey: @"strokeEnd"]; 

}

Is there something in iOS7 that I should know about when working with CAAnimations, etc.? OR is there an error in the code?

Please note that this code was obtained from: How do you achieve the โ€œwipeโ€ / radial deletion effect in iOS?

0
ios cabasicanimation
source share
1 answer

I think the problem (or at least part of it) could be this:

 [_resultsImage setFrame:_imageView.bounds]; 

It must read

 [_resultsImage setBounds:_imageView.bounds]; 

Instead. If you set FRAME to the image frames, you will move the image to 0.0 in its supervisor.

I also do not understand what _imageView is, not _resultsImage.

I would step over your code in the debugger by looking at the rectangles of the frame that are set for the image layer and mask layer, and all other calculated values.

+1
source share

All Articles