2010-09-08 12 views
13

मैं लेबल या छवि के आंदोलन को कैसे एनिमेट कर सकता हूं? मैं बस स्क्रीन पर एक स्थान से दूसरे स्थान पर धीमा संक्रमण करना चाहता हूं (कुछ भी कल्पना नहीं)।आईओएस - किसी लेबल या छवि का एनिमेट आंदोलन

उत्तर

12

आप और -commitAnimationsUIView पर विधियों की तलाश में हैं।

संक्षेप में, आप की तरह कुछ कार्य करें:

[UIView beginAnimations:nil context:NULL]; // animate the following: 
myLabel.frame = newRect; // move to new location 
[UIView setAnimationDuration:0.3]; 
[UIView commitAnimations]; 
+0

बिल्कुल सही! आपका बहुत बहुत धन्यवाद :) – Nippysaurus

13

iOS4 के लिए और बाद में आप beginAnimations:context और commitAnimations उपयोग नहीं करना चाहिए, क्योंकि ये documentation में हतोत्साहित किया जाता है।

इसके बजाय आपको ब्लॉक-आधारित विधियों में से एक का उपयोग करना चाहिए।

ऊपर के उदाहरण तो इस प्रकार दिखाई देगा:

[UIView animateWithDuration:0.3 animations:^{ // animate the following: 
    myLabel.frame = newRect; // move to new location 
}]; 
3

यहाँ एक UILabel साथ एक उदाहरण है - एनीमेशन 0.3 सेकंड में बाएं से लेबल स्लाइड।

// Save the original configuration. 
CGRect initialFrame = label.frame; 

// Displace the label so it's hidden outside of the screen before animation starts. 
CGRect displacedFrame = initialFrame; 
displacedFrame.origin.x = -100; 
label.frame = displacedFrame; 

// Restore label's initial position during animation. 
[UIView animateWithDuration:0.3 animations:^{ 
    label.frame = initialFrame; 
}]; 
संबंधित मुद्दे