소리를 재생하는 NIB 파일에이 단추를 아래에 호출합니다.CABasic은 애니메이션 완성 후 이미지를 제거하지 않습니다.
-(void) animateHeart
{
heartLayer = [[CALayer alloc] init];
[heartLayer setBounds:CGRectMake(0.0, 0.0, 85.0, 85.0)];
[heartLayer setPosition:CGPointMake(150.0, 100.0)];
UIImage *heartImage = [UIImage imageNamed:@"heart.png"];
CGFloat nativeWidth = CGImageGetWidth(heartImage.CGImage)/3;
CGFloat nativeHeight = CGImageGetHeight(heartImage.CGImage)/3;
CGRect startFrame = CGRectMake(165.0, 145.0, nativeWidth, nativeHeight);
heartLayer.contents = (id)heartImage.CGImage;
heartLayer.frame = startFrame;
[self.view.layer addSublayer:heartLayer];
CABasicAnimation *theAnimation;
theAnimation=[CABasicAnimation animationWithKeyPath:@"opacity"];
theAnimation.duration=2.5;
theAnimation.repeatCount=2;
theAnimation.speed = 1.85;
theAnimation.autoreverses=YES;
theAnimation.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseInEaseOut];
theAnimation.fromValue=[NSNumber numberWithFloat:0.0];
theAnimation.toValue=[NSNumber numberWithFloat:1.0];
[theAnimation setValue:heartLayer forKey:@"parentLayer"];
[heartLayer addAnimation:theAnimation forKey:@"animateOpacity"];
theAnimation.fillMode = kCAFillModeRemoved;
theAnimation.removedOnCompletion = YES;
}
방법은 완벽하게 잘하지만 그렇게 한 후, 이미지가 true로 removedOnCompletion BOOL을 설정하는 데에도 불구하고보기에 거기에 매달려 남아있는 이미지를 애니메이션. 애니메이션이 완성되면 이미지를 사라지게하고 싶습니다. 내가 여기 올 수있는 도움을 주시면 감사하겠습니다.
미리 감사드립니다.
나는 델리게이트를 추가하는 것을 잊어 버리고있었습니다. 친절하게 도와 주셔서 대단히 감사합니다! –
@RehatKathuria 환영합니다! 응답이 효과가있는 경우 대답 옆에있는 체크 표시의 개요를 클릭하여 수락을 고려하십시오. 이렇게하면 다른 사람들에게 더 이상 더 좋은 대답을 찾고, Stack Overflow에서 아주 새로운 배지를 얻을 수 있습니다. – dasblinkenlight