2009-09-24 20 views
5

के साथ UIButton अल्फा प्रॉपर्टी को एनिमेट कैसे कर सकता हूं मेरे पास एक अल्फा प्रॉपर्टी के साथ एक साधारण UIButton है जिसे मैं 1.0f से 0.0f तक एनिमेट करना चाहता हूं, और फिर 1.0f पर एनिमेट करना चाहता हूं। यह मूल रूप से टचडाउन का जवाब दे रहा है।मैं मोनो टच

इसके अलावा, क्या मुझे कुछ खास करने की ज़रूरत है यदि मैं जिस दिन से कॉल कर रहा हूं वह मुख्य धागे पर नहीं है (Async प्रतिनिधि थ्रेडपूल पर आक्रमण किया जाता है)?

क्या मुझे 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

iPhone कोड पोस्ट के लिए धन्यवाद।

दूसरा उत्तर वैश्विक चर का उपयोग कर रहा है और कॉलबैक के लिए पैरामीटर को छोड़ देता है। आज मैंने पहले जवाब के आधार पर यह पता लगाया है।

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(); 
} 
संबंधित मुद्दे