2011-05-28 5 views
6

मैंने अपने अल्फा मानों को बदलकर आईफोन पर छवियों को फीका और आउट करने के तरीके पर कुछ ट्यूटोरियल देखे हैं (उदाहरण के लिए here)।आईफोन - क्या केंद्र से बाहर की छवि को प्रदर्शित करने वाली एनीमेशन बनाना संभव है?

ठीक है, हालांकि मैं कुछ अलग हासिल करने की कोशिश कर रहा हूं; पूरी छवि लुप्त हो जाने के बजाय, मैं छवि को एनिमेटेड कर दूंगा ताकि समय के साथ यह छवि के केंद्र से किनारे (और इसके विपरीत) तक प्रदर्शित हो।

तो एनीमेशन की शुरुआत में मैं छवि को स्क्रीन पर प्रदर्शित नहीं करना चाहता हूं और फिर केंद्र बिट से शुरू होने वाली एनीमेशन की अवधि के दौरान छवि तब तक प्रदर्शित होती है जब तक हम अंत तक नहीं पहुंच जाते छवि स्क्रीन पर प्रदर्शित होता है।

मुझे उन पंक्तियों के साथ कुछ भी नहीं मिल रहा है, क्या किसी को पता है कि आईफोन पर यह संभव होगा? कोई विचार/लिंक जो उपयोगी हो सकता है?

उत्तर

4

यह हासिल करने के लिए काफी आसान होना चाहिए - UIImageView को चीज़ धारण करना, सामग्री को UIViewContentModeCenter पर सेट करें, फिर फ्रेम चौड़ाई/ऊंचाई से फ्रेम में परिवर्तन को एनिमेट करने के लिए कोरएनीमेशन ब्लॉक का उपयोग करें और पूर्ण क्षेत्र होने के लिए केंद्रित आप कवर करना चाहते हैं।

उदा।

/* coming into here, imageView is a suitable UIImageView, 
    frameToFill is a CGRect describing the area the image 
    view should cover when fully unfurled */ 

// set up image view: content mode is centre so that the current 
// frame doesn't affect image sizing, and we'll be keeping the same 
// centre throughout so it won't move. The initial frame is on the 
// centre and of zero size. The view contents are clipped to the view's 
// bounds so that the changing frame does actually cut off the image 
imageView.contentMode = UIViewContentModeCenter; 
imageView.frame = CGRectMake(frameToFill.origin.x + frameToFill.size.width*0.5f, 
          frameToFill.origin.y + frameToFill.size.height*0.5f, 
          0.0f, 0.0f); 
imageView.clipsToBounds = YES; 

// set up an animation block, lasting 3 seconds, in which the 
// only thing animated is the view's frame, expanding back out 
// to the original 
[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:3.0f]; 
    imageView.frame = frameToFill; 
[UIView commitAnimations]; 

आपके दृश्य का किनारा कठिन और आयताकार होगा। यदि आप कुछ और सूक्ष्म चाहते हैं, तो शायद आप CoreAnimation के साथ इसे प्राप्त करने में सक्षम नहीं होंगे; कोरग्राफिक्स स्तर पर उतरना शायद दिन का आदेश है।

+0

हाय टॉमी, अच्छा लगता है, जब मैं ऊपर लागू करता हूं तो कोई एनीमेशन नहीं होता है, छवि अंतिम स्थिति में प्रदर्शित होती है (यानी फ्रेम छवि से भरा हुआ है)। मैंने [UIView सेटएनीमेशन अवधि: 5] जोड़ने की कोशिश की है; एनीमेशन के लिए कोई फायदा नहीं हुआ? मैं क्या गलत कर रहा हूं? आपकी सहायताके लिए धन्यवाद! – MattStacey

+3

@MattStacey गुण 'imageView.clipsToBounds' और/या' imageView.layer.masksToBounds' गुणों को सेट करने का प्रयास करें। डिफ़ॉल्ट रूप से, sublayers clipped नहीं हैं। – benzado

+0

@benzado imageView.ClipsToBounds का उपयोग कर मेरे लिए काम किया, धन्यवाद। – MattStacey

2

एक सरल (और संभवतः नहीं सबसे अच्छा) (कोई यह काम करता है की गारंटी देता है) की कोशिश करने के बात एक imageView बनाने के लिए है और कोनों दौर जब तक यह परिपत्र है, कुछ इस तरह:

[imageView.layer setCornerRadius:60.0f]; 
    [imageView.layer setMasksToBounds:YES]; 
    [imageView.layer setBorderWidth:0.0f]; 

प्रारंभिक imageView सेट छोटा (1 पीएक्स द्वारा 1 पीएक्स)। फिर कुछ सरल एनीमेशन कोड का उपयोग करें:

[UIView beginAnimations:nil context:NULL]; { 
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
    [UIView setAnimationDelay:2.0]; 
    [UIView setAnimationDuration:1.0]; 
    [UIView setAnimationDelegate:self]; 
    // set the imageView to the size you want here 
} [UIView commitAnimations]; 
0

इस कोड को आज़माएं।

एक छवि दृश्य बनाएं।

UIImageView *imgv = [[UIImageView alloc]initWithFrame: 
              CGRectMake(0, 0, 0, 0)]; 
imgv.image = [UIImage imageNamed:@"black.png"]; 

//position the imageview to the center of the screen. 
imgv.center = self.view.center; 
    [self.view addSubview:imgv]; 
    [imgv release]; 

//now give the imageview a new frame of full size with an animation 

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:1.0]; 

//i am assuming that your full frame is 320x480 
    imgv.frame = CGRectMake(0, 0, 320, 480); 

[UIView commitAnimations]; 

अब छविदृश्य इसे भरने के लिए स्क्रीन के केंद्र से स्केलिंग प्रतीत होता है।

संबंधित मुद्दे