2010-04-04 4 views
0

나는 초보자이며 도움이 필요합니다.이 애니메이션 코드는 어떻게 사용할 수 있습니까?

주어진 UIView에서 팝업 이미지를 표시하고 싶지만 UIAlertView처럼 동작하거나 iPhone 모달 팝업 창에 대한 Facebook Connect와 같이 멋지고 튼튼한 밴드 모양의 애니메이션이 필요합니다. 그것에.

비슷한 것을하려고하는 사람으로부터 그물에 어떤 코드가 있음을 발견했습니다. 그/그녀는 이것을 집어 넣었지만 데모 나 지시 사항은 없었습니다.

나는 너무 새롭기 때문에 이것을 내 코드에 통합하는 방법에 대해서는 전혀 모른다. 당신이 내게 줄 수있는 모든 도움에 미리

float pulsesteps[3] = { 0.2, 1/15., 1/7.5 }; 
- (void) pulse { 
    self.transform = CGAffineTransformMakeScale(0.6, 0.6); 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:pulsesteps[0]]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(pulseGrowAnimationDidStop:finished:context:)]; 
    self.transform = CGAffineTransformMakeScale(1.1, 1.1); 
    [UIView commitAnimations]; 
} 

- (void)pulseGrowAnimationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:pulsesteps[1]]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(pulseShrinkAnimationDidStop:finished:context:)]; 
    self.transform = CGAffineTransformMakeScale(0.9, 0.9); 
    [UIView commitAnimations]; 
} 

- (void)pulseShrinkAnimationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context { 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:pulsesteps[2]]; 
    self.transform = CGAffineTransformIdentity; 
    [UIView commitAnimations]; 
} 

감사 :

- (void) showProductDetail 
{ 
. . . 
    //////////////////////////////////////////////////////////////////////// 
    // THIS IS A STRAIGHT SCALE ANIMATION RIGHT NOW. I WANT TO REPLACE THIS 
    // WITH A BOUNCY RUBBER-BAND ANIMATION 
     _productDetail.transform = CGAffineTransformMakeScale(0.1,0.1); 
     [UIView beginAnimations:nil context:NULL]; 
     [UIView setAnimationDuration:0.5]; 
     _productDetail.transform = CGAffineTransformMakeScale(1,1); 
     [UIView commitAnimations];  
    } 
. . . 
} 

이것은 내가 찾은 코드는 다음과 같습니다

내가 표시 탄력 이미지를 필요로하는 루틴입니다.

+0

문제가 해결되면 Felixyz의 대답을 받아 들여야합니다. – neha

답변

2

아주 간단합니다. showProductDetail 메서드에서 애니메이션 블록을 시작한 다음 _productDetail.transform 속성을 설정하고 블록을 커밋합니다. 이것이 애니메이션을 만드는 이유입니다.

찾은 코드는 이러한 애니메이션 체인을 수행하도록 설계되었지만 수정되는 속성은 _productDetail 대신에 self에 있습니다. _productDetail이 자신이 만든 클래스의 인스턴스 인 경우 해당 클래스 안에 애니메이션 코드를 넣을 수 있습니다.

그렇지 않은 경우 pulse 메서드 내부의 코드를 showProductDetail 메서드로 옮기고이 메서드 아래에 다른 두 메서드를 넣으면됩니다. 세 가지 방법 모두에서 self.transform_productDetail.transform으로 바꿉니다.

관련 문제