मुझे एक UILabel मिला है जो उपयोगकर्ता स्कोर प्रदर्शित करता है। और समय-समय पर परिवर्तनों को स्कोर करते हैं, क्या इस परिवर्तन को एनिमेट करने का कोई तरीका है, धीरे-धीरे इस संख्या को अपने वर्तमान मूल्य से इसके परिणाम मूल्य में बढ़ाएं? कुछ http://josheinstein.com/blog/index.php/2010/02/silverlight-animated-turbotax-number-display/ की तरह लेकिन उद्देश्य-सी के लिए।UILabel एनिमेटिंग संख्या परिवर्तन
उत्तर
कुछ समय के दौरान UILabel के कस्टम उप-वर्ग की टेक्स्ट प्रॉपर्टी को बदलने के लिए CADisplayLink का उपयोग करें। आप शायद सुंदर आउटपुट के लिए NSNumberFormatter
का उपयोग करना चाहेंगे।
// Create instance variables/properties for: `from`, `to`, and `startTime` (also include the QuartzCore framework in your project)
- (void)animateFrom:(NSNumber *)aFrom toNumber:(NSNumber *)aTo {
self.from = aFrom; // or from = [aFrom retain] if your not using @properties
self.to = aTo; // ditto
self.text = [from stringValue];
CADisplayLink *link = [CADisplayLink displayLinkWithTarget:self selector:@selector(animateNumber:)];
startTime = CACurrentMediaTime();
[link addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
}
- (void)animateNumber:(CADisplayLink *)link {
static float DURATION = 1.0;
float dt = ([link timestamp] - startTime)/DURATION;
if (dt >= 1.0) {
self.text = [to stringValue];
[link removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
return;
}
float current = ([to floatValue] - [from floatValue]) * dt + [from floatValue];
self.text = [NSString stringWithFormat:@"%i", (long)current];
}
नोट, यदि आप 'NSNumberFormatter' का उपयोग करते हैं, तो उनमें से एक बनाएं और उसी प्रारूप का उपयोग करने वाले प्रत्येक स्वरूपण कार्य के लिए इसका पुन: उपयोग करें। एक नया 'NSNumberFormatter' बनाना काफी महंगा है, लेकिन मौजूदा एक का उपयोग करना सस्ता है। –
मैं पर फ्लोट वर्तमान = ([फ्लोट वैल्यू] के लिए EXC_BAD_ACESS प्राप्त कर रहा हूं - [फ्लोटवेल्यू से]] * डीटी + [फ्लोटवेल्यू से] '; – Drabuna
क्या आप 'से'' और 'से' चर के लिए गुणों का उपयोग कर रहे हैं? और क्या यह 'बनाए रखने' के लिए सेट है? यदि आप गुणों का उपयोग नहीं कर रहे हैं तो 'से = [एफ़्रोम बनाए रखें] ' –
AUIAnimatedText
वह सब कुछ है जिसे आप पूछ रहे थे। यह UILabel के लिए पहुंच टेक्स्ट एनिमेटिंग संभावनाओं के साथ प्रतिस्थापन है,
- 1. एक स्पंदन UILabel एनिमेटिंग?
- 2. UILabel के एनिमेटिंग फ़्रेम को आसानी से
- 3. एनिमेटिंग सूचीदृश्य डेटा परिवर्तन
- 4. आईओएस ऐप में CoreAnimation/QuartzCore के साथ UILabel एनिमेटिंग
- 5. UILabel टेक्स्ट में परिवर्तन का पता लगाएं
- 6. एनिमेटिंग UIButton टेक्स्ट रंग
- 7. JQuery Knob प्रदर्शन संख्या परिवर्तन
- 8. UILabel
- 9. UILabel
- 10. uilabel
- 11. UIlabel
- 12. UILabel
- 13. UILabel
- 14. UILabel
- 15. UILabel
- 16. UILabel
- 17. UILabel
- 18. UILabel
- 19. UILabel -
- 20. uilabel
- 21. अग्रभूमि एनिमेटिंग CATextLayer
- 22. मल्टीलाइन UILabel?
- 23. आईओएस - UILabel या UITextView में पाठ आकार परिवर्तन को एनिमेट करना?
- 24. एनिमेटिंग jQuery यूआई स्थिति()
- 25. एक कैलियर छायापाथ एनिमेटिंग
- 26. फ्रैगमेंट मानक संक्रमण एनिमेटिंग
- 27. एनिमेटिंग UITextInput के textInputView
- 28. एंड्रॉइड एनिमेटिंग एनीमेशन-सूची
- 29. एनिमेटिंग निकालें FromSuperview
- 30. UILabel के लिए अलग अस्पष्टता और UILabel
मैंने पाया कि उत्तर के लिए http://stackoverflow.com/questions/3073520/setting-new-text-to-uilabel-and-animation ** पहले देखो उपयोगी हो सकता है * * – wczekalski
हाँ, मैंने इसे देखा, बिल्कुल एनीमेशन नहीं जिसे मैं ढूंढ रहा हूं। – Drabuna