hI,
I am workng on animation using CALayer and CAPath.
Here I am animating an Image from top to bottom of screen.I gave starting and ending position for
the animation.Now, I want to get position during the animation.
Sample Code:
- (void)onTimer
{
CGImageRef imageRef = [[UIImage imageNamed:@"apple.png"] CGImage];
int startX = round(random() % 460);
double speed = 1/round(random() %100) + 1.0;
layer = [CALayer layer];
layer.name = @"layer";
layer.contents = (id)imageRef; // cached image
layer.frame = CGRectMake(startX, self.view.frame.size.height+10, CGImageGetWidth(imageRef), CGImageGetHeight(imageRef));
[mView.layer addSublayer:layer];
path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, startX, -100);
CGPathAddLineToPoint(path, NULL, startX, self.view.frame.size.height+10);
CAKeyframeAnimation *animation= [CAKeyframeAnimation animationWithKeyPath:@"position"];
animation.delegate=self;
animation.duration= 10*speed;
animation.autoreverses=NO;
animation.path=path;
animation.repeatCount = 0;
animation.removedOnCompletion=YES;
animation.calculationMode = kCAAnimationLinear;
[layer addAnimation:animation forKey:@"position"];
CGPoint point= CGPathGetCurrentPoint(path);
}
In this I used "CGPathGetCurrentPoint" method but it did not work. Also used
presentationLayer method of CALayer but uit also did not work in this case.
Can anyone suggest the code to get the position during animation
thanks in advance
1
A
답변
1
Core Animation은이를 위해 설계되지 않았습니다. 그것의 임무는 여러분을 위해 속성 애니메이션을 다루는 것이지 당신을 그것에 노출시키지 않는 것입니다.
애니메이션 중에 위치를 알고 싶다면 Core Animation없이 모든 애니메이션을 직접 수행해야합니다.
CGPathGetCurrentPoint()
은 코어 애니메이션 키 프레임 애니메이션 경로가 아닌 CGPath
인스턴스의 제어점에 액세스하는 기능입니다.
2
레이어의 presentationLayer에서 속성을 보면 애니메이션 중에 화면에 표시되는 값을 얻을 수 있습니다.
관련 문제
- 1. iPhone에서 위치를 안정적으로 얻는 방법
- 2. CALayer : 애니메이션 종료시 콜백?
- 3. 애니메이션 CALayer 숨기기
- 4. 코어 애니메이션 CALayer 마스크 애니메이션 성능
- 5. 클릭의 위치를 얻는 방법?
- 6. DOM의 위치를 기반으로 요소 이름을 얻는 중
- 7. CALayer 속성의 애니메이션 시간을 변경하십시오.
- 8. CALayer/CABasicAnimation 불투명도 애니메이션 캐시?
- 9. iPhone에서 MKReverseGeocoder를 사용하여 주소 및 전화 번호를 얻는 방법
- 10. 위치를 얻는 방법
- 11. 사용자 지정 작업에서 setup.exe의 위치를 얻는 중
- 12. iPhone에서 작동하지 않는 암시 적 애니메이션
- 13. Qt에서 레이블의 마우스 클릭 위치를 얻는 중
- 14. 사용자 정의 CALayer 속성에 애니메이션 적용
- 15. iPhone에서 사용자 입력을 얻는 방법
- 16. CALayer 필터 및 경계
- 17. android에서 현재 위치를 얻는 방법
- 18. iPhone에서 GPS로 현재 위치를 확인하는 방법
- 19. iPhone에서 스크롤보기를 사용하는 방법?
- 20. 요소의 상단 위치를 얻는 방법?
- 21. gwt 현재 위치를 얻는 방법?
- 22. 웹 요청의 위치를 얻는 방법?
- 23. 아이폰에서 GPS 위치를 얻는 방법
- 24. TreeView에서 하위 위치를 얻는 방법?
- 25. 하위 요소의 위치를 얻는 방법
- 26. 키보드에서 키의 위치를 얻는 방법
- 27. 모든 문자의 위치를 얻는 방법
- 28. Android - 친구의 위치를 얻는 방법
- 29. UIView 애니메이션 중에 CALayer 그림자가 사라짐
- 30. CALayer - 애니메이션에서 레이어 크기 블록 애니메이션 실행