2012-03-30 16 views
31

मैं अपने आईफोन ऐप में "पॉप-इन" स्क्रीन पर बस दिखने की बजाए एक छवि रखना चाहता हूं। "पॉप-इन" से मेरा मतलब है कि यह एक छोटे से बिंदु से अपने वास्तविक आकार में बढ़ेगा। संदर्भ के लिए, यह मुख्य रूप से मुख्य पॉप में "पॉप" एनीमेशन प्रभाव जैसा ही है। मैं आईओएस एनिमेशन के लिए पूरी तरह से नया हूं, इसलिए यदि कोई मुझे एनीमेशन प्रभावों की दिशा में इंगित कर सकता है तो मुझे इसका उपयोग करने की आवश्यकता होगी, इसकी सराहना की जाएगी।आईओएस - एनीमेशन प्रभाव - छवि पॉप-इन

धन्यवाद

ब्रायन

अद्यतन मैं नीचे दिए गए सुझावों से इस कोड को जोड़ दिया है। यह काम करता है लेकिन यह मेरी छवि को नीचे की बजाय स्केल करता है। मुझे पता है कि ऐसा इसलिए है क्योंकि मेरे पास 0.01 ट्रांसफॉर्म स्केल आकार के रूप में है, लेकिन मैं जानना चाहता हूं कि मैं आकार 0.0 की छवि के साथ कैसे शुरू कर सकता हूं और 1 तक स्केल कर सकता हूं। क्या यह मेरी छवि का आकार सेट करना सिर्फ एक मामला है 0? धन्यवाद

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration: 0.2]; 
image.transform = CGAffineTransformMakeScale(0.01, 0.01); 
[UIView setAnimationDelegate:self]; 
[UIView commitAnimations]; 

उत्तर

78

प्रभाव आप देख रहे हैं कुछ इस तरह है:

// instantaneously make the image view small (scaled to 1% of its actual size) 
view.transform = CGAffineTransformMakeScale(0.01, 0.01); 
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ 
    // animate it to the identity transform (100% scale) 
    view.transform = CGAffineTransformIdentity; 
} completion:^(BOOL finished){ 
    // if you want to do something once the animation finishes, put it here 
}]; 
+1

क्या केंद्र से अलग बिंदु से छवि को स्केल-अप करने का कोई तरीका है? – tiguero

+5

Yep- अपनी परत [एंकर पॉइंट] बदलें (http://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CALayer_class/Introduction/Introduction.html#//apple_ref/doc/c_ref/CALayer) । 'TheView।layer.anchorPoint = CGPointMake (0, 0) 'दृश्य स्केल को अपने शीर्ष बाएं से बना देगा; '(1, 1) 'इसका निचला दायां है। –

+0

परिवर्तनीय छवि किस प्रकार की वस्तु है? –

0

आप को देखने के फ्रेम चेतन करने के लिए, अंतिम अवस्था शून्य से यह छोटा करने के लिए किया है। यह उदाहरण के लिए UIView ब्लॉक एनीमेशन के साथ किया जा सकता है।

तो उदाहरण के लिए अंतिम दृश्य और स्थिति के साथ आईबीओलेट संपत्ति self.myView के रूप में अपने दृश्य के साथ शुरू करें, लेकिन छुपा ध्वज सेट करें। तो फिर तुम यह प्रयोग प्रकट करने के लिए निम्नलिखित चाहते हैं जब:

// Save old frame as final stater and set it to zero size for the start of the animation 
// But keep the same center position, so it just grows and don't move around 
CGRect oldFrame = self.myView.frame; 
CGRect oldCenter = self.myView.center; 

self.myView.frame = CGRectZero; 
self.myView.center = oldCenter; 

self.myView.hidden = NO; 

NSTimeInterval duration = 0.3; 

[UIView animateWithDuration:duration delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{ 
       // New position and size after the animation should be the same as in Interface Builder 
       self.myView.frame = oldFrame 
    } 
        completion:^(BOOL finished){ 
               // You can do some stuff here after the animation finished 
        }]; 
+0

वह ... शायद अच्छी तरह से काम नहीं करेगा। एक छवि दृश्य के फ्रेम को एनिमेट करना इसे एनीमेशन के हर फ्रेम पर खुद को फिर से चलाने के लिए मजबूर करता है। –

+1

@ नोहा विदरस्पून एक बेहतर तरीका बदल जाएगा? – Thyraz

+0

यूप। CGAffineTransformMakeScale (0.01,0.01) से CGAffineTransformIdentity को एनिमेट करना चाल चल जाएगा। –

0

स्विफ्ट 2.0 संस्करण

view.transform = CGAffineTransformMakeScale(0.01, 0.01); 

    UIView.animateWithDuration(0.2, delay: 0, options: .CurveEaseOut, animations: {() -> Void in 
     // animate it to the identity transform (100% scale) 
     self.view.transform = CGAffineTransformIdentity; 

     }) { (finished) -> Void in 
     // if you want to do something once the animation finishes, put it here 
    } 
4

आप अगर जैसे कुछ चाहते हैं फेसबुक किसी भी पोस्ट को पसंद करने पर करता है तो इस

का उपयोग करें जब आप दृश्य चेतन करने के लिए

अगर आप बटन पर पाठ और छवि है और आप सिर्फ बटन की छवि चेतन करने के लिए तो बस "btn के साथ" btn "की जगह चाहते हैं

-(void)animateButton:(UIButton *)sender{ 
UIButton * btn = (UIButton *)sender; 
[UIView animateWithDuration:0.3/1.5 animations:^{ 
    btn.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.4, 1.4); // scales up the view of button 
} completion:^(BOOL finished) { 
    [UIView animateWithDuration:0.3/2 animations:^{ 
     btn.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.7, 0.7);// scales down the view of button 
    } completion:^(BOOL finished) { 
     [UIView animateWithDuration:0.3/2 animations:^{ 
      btn.transform = CGAffineTransformIdentity; // at the end sets the original identity of the button 
     }]; 
    }]; 
}];} 

सिर्फ इस विधि कॉल। imageView ", यह सिर्फ बटन की छवि दृश्य संपत्ति पर एनीमेशन उत्पन्न करेगा। उम्मीद है कि यह मदद करता है सभी बेहतरीन।

0
है कि आप एक सरल UIView

उपयोग करने के लिए अपने वर्तमान दृश्य का UIView जोड़े होगा के लिए

- (void) initPopUpView 
{ 
    popup.alpha = 0; 
    popup.frame = CGRectMake (160, 240, 0, 0); 
    [self.view addSubview:popup]; 
} 

- (void) animatePopUpShow 
{ 
    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:0.3]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationWillStartSelector:@selector(initPopUpView)]; 

    popup.alpha = 1; 
    popup.frame = CGRectMake (20, 40, 300, 400); 

    [UIView commitAnimations]; 
} 
संबंधित मुद्दे