2014-05-14 4 views
0

나는 현재 코드를 컨테이너 주변의 버튼을 무작위로 움직여야합니다. 내가 원하는 것은 그것이 나타나고, 사라지고, 다른 곳에서 나타나는 것입니다. 그러나 그것은 전체적으로 볼 수 있습니다.애니메이션 도중 버튼 숨기기

애니메이션을 다시 배치하는 동안 어떻게 숨길 수 있습니까?

-(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; 
} 

답변

-1

대신 NSTimer를 사용하여 단추를 이동했습니다. 매초 움직였습니다.

0

self.button.hidden = YES;을 사용하여이를 숨길 수 있습니다. 다시 표시하려면 숨김을 NO로 설정하십시오.

+0

처럼 그것을 시도 할 수있는 다른 위치에 표시 내가 그것을 사용할 때 다시 가져와. 추천 코드를 반영하도록 코드를 수정했습니다. 왜 돌아 오지 않는지 아십니까? –

+1

함수의 시작 부분에서 hidden을 NO로 설정 했으므로 함수의 끝에서 hidden = YES로 설정합니다. beginAnimations와 commitAnimations 사이에이 코드를 넣어야합니다. –

+1

더 나은 것은 UIView 애니메이션 블록을 사용해야한다는 것입니다. 사용중인 코드는 오랫동안 블록으로 대체되었습니다. –

0

는 내가 제대로 질문을 이해 있는지 확실하지 않습니다하지만 당신이 원하는 경우에있는 UIButton가 사라 한 다음 그런 다음되지 그것을 숨길 것 그

[UIView animateWithDuration:1.0 animations:^{ 
    self.button.alpha = 0; 
} completion:^(BOOL finished) { 
    if (finished) { 
     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); 
     self.button.centre = squarePosition; 
     [UIView animateWithDuration:1.0 animations:^{ 
       self.button.alpha = 1.0; 
      }]; 
     } 
    }]; 
관련 문제