"고정 된"이미지가 손가락으로 움직여서 원래 위치로 되돌아가는 간단한 앱을 만들려고합니다. 이것은 아마도 코드로 더 잘 설명 될 것입니다 :CGAffineTransform 상호 작용 이해하기
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
image.transform = CGAffineTransformIdentity;
}
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
if (CGRectContainsPoint([image frame], [touch locationInView:nil]))
{
image.center = [touch locationInView:nil];
}
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if (pin) {
CGPoint point = image.center;
CGPoint center = self.view.center;
//CGAffineTransform transform = CGAffineTransformMakeTranslation(0, 0);
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
image.transform = CGAffineTransformMakeTranslation(center.x - point.x, center.y - point.y);
//image.transform = CGAffineTransformConcat(image.transform, CGAffineTransformMakeTranslation(center.x - point.x, center.y - point.y));
[UIView commitAnimations];
}
}
이미지를 누를 때마다 손가락 아래에서 밖으로 움직 이도록 이미지가 누를 때마다 움직입니다. 나는 그것이 변형과 관련이 있다고 생각합니다. 누구든지 올바른 방향으로 나를 가리킬 수 있었습니까?
잘 했어! UITouch * touch = [[allTouches] anyObject]]를 추가해야했습니다. 코드가 작동하려면 (또한 경계를 확인해야합니다). 고맙습니다! – Eric