내가 다음 코드 작성 :UIImageView 위치 확인 문제가 있습니까?
-(void)viewDidLoad{
JumpVelocity = 10;
aStandRightArray = [[NSArray alloc] initWithObjects:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"aStandR1" ofType:@"png"]],
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"aStandR2" ofType:@"png"]],
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"aStandR3" ofType:@"png"]],
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"aStandR2" ofType:@"png"]],
nil];
aJumpRightArray = [[NSArray alloc] initWithObjects:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"aJumpR" ofType:@"png"]], nil];
aStandRight = [[UIImageView alloc] initWithFrame:CGRectMake(0, 242, 55, 65)];
aStandRight.animationImages = aStandRightArray;
aStandRight.animationDuration = 0.5;
[self.view addSubview:aStandRight];
aJumpRight = [[UIImageView alloc] initWithFrame:CGRectMake(0, 234, 69, 65)];
aJumpRight.animationImages = aJumpRightArray;
[self.view addSubview:aJumpRight];}
-(IBAction)buttonJumpRight:(id)sender{
[aStandRight stopAnimating];
[aStandRight removeFromSuperview];
[aJumpRight startAnimating];
jumpTimer = [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(playerJumpRight) userInfo:nil repeats:YES];}
-(void)playerJumpRight{
[aJumpRight removeFromSuperview];
aJumpRight.center = CGPointMake(aJumpRight.center.x + JumpVelocity, 234);
[self.view addSubview:aJumpRight];
if(aJumpRight.center.x >= 84.0)
{
[jumpTimer invalidate];
jumpTimer = nil;
[aJumpRight stopAnimating];
aStandRight.center = CGPointMake(84, 242);
[aStandRight startAnimating];
[self.view addSubview:aStandRight];
}
} 기본적으로
내가 여기서 뭘하려고하는 것은 서 애니메이션을로드입니다, 다음 사용자는 내가 서 애니메이션을 언로드 한 후 중지 buttonJumpRight 버튼을 누를 때 . 그 후 점프 애니메이션을로드하고 playerJumpRight 함수를 사용하여 화면을 가로 질러 움직이기 시작합니다.
모든이 개를 제외하고 잘 작동하는 것 같다 :
점프 애니메이션 이동은 x 축을 따라하지만 코드에서 위의 "234입니다 원래의 y 위치를 유지하지 않습니다 어떤 이유로 예상처럼 ".
점프 애니메이션 x 위치는 (84, 242)의 욕망 위치에서 다른 곳으로 문 모든 것이 서 애니메이션 에 대한 기대 새로 만든 위치처럼 작동하는 경우입니다 방법에 대한 요구 사항을 충족합니다.
은 내가 여러 가지 가능한 해결 방법을 시도하고, 꽤 많은 시간을 검색하지만 모든 시도에서 실패하고. 제 ios/objective c를 코딩하기 시작하면서 신비를 용서하십시오.
당신이 제공 할 수있는 도움을 크게 주시면 감사하겠습니다.
정확하게 맞습니다. 중심을 frame.origin과 혼동 시켰습니다. 지난 2 일 동안이 문제로 고생 해 줘서 고마워. 또한 superview에서 제거하지에 대한 팁 주셔서 감사합니다. 나는 내가 superview에서 그것을 제거하고 내가 그것을 가지고 있었던 위치 확인 문제를 고쳐 줄 것이라는 점을 볼 때 그것을 추가 할 때 중심으로 바꿨다 고 생각했다. 그러나 실제로 프레임 원점과 함께 중심의 혼란이었다. 다시 한번 감사드립니다. – RickyTheCoder