나는 현재 코드를 컨테이너 주변의 버튼을 무작위로 움직여야합니다. 내가 원하는 것은 그것이 나타나고, 사라지고, 다른 곳에서 나타나는 것입니다. 그러나 그것은 전체적으로 볼 수 있습니다.애니메이션 도중 버튼 숨기기
애니메이션을 다시 배치하는 동안 어떻게 숨길 수 있습니까?
-(void)animationLoop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
self.button.hidden = NO;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1];
CGFloat x = (CGFloat) (arc4random() % (int) self.container.bounds.size.width);
CGFloat y = (CGFloat) (arc4random() % (int) self.container.bounds.size.height);
CGPoint squarePostion = CGPointMake(x, y);
_button.center = squarePostion;
// add:
[UIView setAnimationDelegate:self]; // as suggested by @Carl Veazey in a comment
[UIView setAnimationDidStopSelector:@selector(animationLoop:finished:context:)];
[UIView commitAnimations];
self.button.hidden = YES;
}
처럼 그것을 시도 할 수있는 다른 위치에 표시 내가 그것을 사용할 때 다시 가져와. 추천 코드를 반영하도록 코드를 수정했습니다. 왜 돌아 오지 않는지 아십니까? –
함수의 시작 부분에서 hidden을 NO로 설정 했으므로 함수의 끝에서 hidden = YES로 설정합니다. beginAnimations와 commitAnimations 사이에이 코드를 넣어야합니다. –
더 나은 것은 UIView 애니메이션 블록을 사용해야한다는 것입니다. 사용중인 코드는 오랫동안 블록으로 대체되었습니다. –