이미지에 홍채 제거 효과를 생성하는 CABasicAnimation이 있습니다. 즉, 애니메이션은 시뮬레이터에서 제대로 작동하지만 기기에는 기쁨이 없습니다. 타이머는 여전히 올바르게 작동하고 animationCompleted 블록이 호출되지만 표시되는 애니메이션은 없습니다. 여기 CABasicAnimation이 기기에서 작동하지 않습니다 (iPhone 5s)
는 조리개가 작동 와이프 얻을 수있는 코드 :- (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's layer.
_resultsImage.layer.mask = maskLayer;
//Set our mask layer's frame to the parent layer's 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"];
}
가 나는 등 CAAnimations로 작업 할 때 알고 있어야 iOS7에 뭔가가 있나요? 또는 코드에 오류가 있습니까?
참고이 코드에서 공급되었다 How do you achieve a "clock wipe"/ radial wipe effect in iOS?
코드에 명백한 오류가 보이지 않습니다. 레이어를 표시하고 애니메이션을 적용하도록 코드를 변경했으나 괜찮을 것입니다. 보기가 표시됩니까? 모양 레이어를보기 레이어의 마스크로 추가하는 코드를 주석 처리하면 어떻게됩니까? 보기의 이미지가 표시됩니까? –
도움말 Duncan에 감사드립니다.보기가 표시되고 애니메이션 기간 동안 볼 수 있으며 완료 블록이 호출되면 화면에서보기가 제거됩니다. 따라서 작동하지 않는 것은 계층화 된 애니메이션뿐입니다. 원본을 iPhone 앱으로 변환하고이를 사용하여 기기에서 테스트를 실행할 수 있습니다. –
github에 문제가있는 프로젝트를 게시하고 여기에 링크를 게시 할 수 있습니까? 내가 한번 볼게. –