2009-09-24 2 views
5

1.0f에서 0.0f로 애니메이트하고 1.0f로 다시 애니메이션하려는 Alpha 속성을 가진 간단한 UIButton이 있습니다. 이것은 기본적으로 TouchDown에 응답합니다.MonoTouch로 UIButton Alpha 속성을 애니메이트하는 방법

또한 내가 호출하는 루틴이 기본 스레드 (비동기 대리자가 ThreadPool에서 호출 됨)에없는 경우 수행해야 할 특별한 작업이 있습니까?

CAAnimation을 사용해야합니까?

감사합니다. 모노 방식을 가진 사람 파이프까지 그것을 할 않는

답변

6

, 내가 말할 사용 :

- (void) pulseButton { 
    button.alpha = 0.0; 
    [UIView beginAnimations:nil context:button]; { 
     [UIView setAnimationDelegate:self]; 
     [UIView setAnimationDidStopSelector:@selector(makeVisibleAgain:finished:context:)]; 
     [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; 
     [UIView setAnimationDuration:0.50]; 
     button.alpha = 0.0; 
    } [UIView commitAnimations]; 
} 
- (void)makeVisibleAgain:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context 
{ 
    UIButton *button = ((UIButton *) context); 
    [UIView beginAnimations:nil context:nil]; { 
     [UIView setAnimationDelegate:nil]; 
     [UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 
     [UIView setAnimationDuration:0.5]; 
     button.alpha = 1.0; 
    } [UIView commitAnimations]; 

} 
+0

매우 모노로 포팅하기 쉽다. – rpetrich

4

이 매우 간단하다 : 아이폰 코드 게시물에 대한

UIView button; 

public void fadeButtonInAndOut() 
{ 
    UIView.BeginAnimations("fadeOut"); 
    UIView.SetAnimationDelegate(this); 
    UIView.SetAnimationDidStopSelector(new Selector("fadeOutDidFinish")); 
    UIView.SetAnimationDuration(0.5f); 
    button.Alpha = 0.0f; 
    UIView.CommitAnimations(); 
} 

[Export("fadeOutDidFinish")] 
public void FadeOutDidFinish() 
{ 
    UIView.BeginAnimations("fadeIn"); 
    UIView.SetAnimationDuration(0.5f); 
    button.Alpha = 1.0f; 
    UIView.CommitAnimations(); 
} 
5

감사합니다.

두 번째 대답은 전역 변수를 사용하고 콜백 매개 변수를 건너 뜁니다. 다음은 첫 번째 대답을 기반으로 오늘 알아 낸 것입니다.

private void BeginPulse (Button button) 
{ 
    UIView.BeginAnimations (button+"fadeIn", button.Handle); 
    UIView.SetAnimationDelegate (this); 
    UIView.SetAnimationDidStopSelector (new MonoTouch.ObjCRuntime.Selector ("makeVisibleAgain:finished:context:")); 
    UIView.SetAnimationCurve(UIViewAnimationCurve.EaseOut); 
    UIView.SetAnimationDuration (0.5); 
    button.Alpha = 0.25f; 
    UIView.CommitAnimations(); 
} 

[Export ("makeVisibleAgain:finished:context:")] 
private void EndPulse (NSString animationId, NSNumber finished, UIButton button) 
{ 
    UIView.BeginAnimations (null, System.IntPtr.Zero); 
    UIView.SetAnimationDelegate (this); 
    UIView.SetAnimationCurve (UIViewAnimationCurve.EaseIn); 
    UIView.SetAnimationDuration (0.5); 
    button.Alpha = 1; 
    UIView.CommitAnimations(); 
} 
관련 문제