2014-03-31 3 views
0

이미지에 홍채 제거 효과를 생성하는 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?

+0

코드에 명백한 오류가 보이지 않습니다. 레이어를 표시하고 애니메이션을 적용하도록 코드를 변경했으나 괜찮을 것입니다. 보기가 표시됩니까? 모양 레이어를보기 레이어의 마스크로 추가하는 코드를 주석 처리하면 어떻게됩니까? 보기의 이미지가 표시됩니까? –

+0

도움말 Duncan에 감사드립니다.보기가 표시되고 애니메이션 기간 동안 볼 수 있으며 완료 블록이 호출되면 화면에서보기가 제거됩니다. 따라서 작동하지 않는 것은 계층화 된 애니메이션뿐입니다. 원본을 iPhone 앱으로 변환하고이를 사용하여 기기에서 테스트를 실행할 수 있습니다. –

+0

github에 문제가있는 프로젝트를 게시하고 여기에 링크를 게시 할 수 있습니까? 내가 한번 볼게. –

답변

1

나는 문제 (또는 적어도 일부)이 선 것 같아요 :

[_resultsImage setFrame:_imageView.bounds]; 

읽어야

[_resultsImage setBounds:_imageView.bounds]; 

대신. 프레임을 이미지 뷰의 범위로 설정하면 슈퍼 뷰에서 이미지 뷰를 0.0으로 이동하게됩니다.

또한 _resultsImage와는 대조적으로 _imageView가 무엇인지 명확하지 않습니다.

이미지보기 및 마스크 레이어에 대해 설정된 프레임 사각형과 계산 된 다른 모든 값을보고 디버거에서 코드를 단계별로 실행합니다.

+0

안녕 던컨! :) 감사합니다 :) 불행히도 나는 이것을 추구 할 시간이 없었고 작은 애니메이션 시퀀스를 넣어야했지만 다른 프로젝트에서 테스트를 실행했지만이 코드로 작업하는 것 같습니다. 도와 주셔서 다시 한 번 감사드립니다! 만약 내가 당신이 도전적으로 세계의 반대편에있는 맥주 한 상자를 사 줄 수있는 앱이 있다면 : –

+1

@TaylorAbernethyNewman, 그런 앱이 있었다면 ** 그 맥주를 마셔. :) –

관련 문제