2010-09-17 8 views
13

छवि का उपयोग कर रहा कोड im मेरे ऐप के इस टुकड़े था:आईओएस 4.2: फ्लिप ब्लॉक एनिमेशन

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:1]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:imgView cache:YES]; 
    imgView.image = img2; 
[UIView commitAnimations]; 

लेकिन इस पद्धति के उपयोग आईओएस 4.0 में हतोत्साहित किया और बाद में, और मैं transitionWithView:duration:options:animations:completion:

का उपयोग करना चाहिए है मैं इसे ठीक से काम करने के लिए नहीं मिल सकता। क्या कोई मेरी मदद कर सकता है? Thx!

उत्तर

19
[UIView transitionWithView:imgView // use the forView: argument 
        duration:1   // use the setAnimationDuration: argument 
        options:UIViewAnimationOptionTransitionFlipFromLeft 
          // check UIViewAnimationOptions for what options you can use 
       animations:^{   // put the animation block here 
           imgView.image = img2; 
          } 
       completion:NULL];  // nothing to do after animation ends. 
+0

धन्यवाद एक बहुत! एक जादू की तरह काम करता है। – FransGuelinckx

+0

@ केनीटीएम: क्या आप [ब्लॉक के लिए नल बनाम शून्य] का उपयोग करके स्पष्ट करने में सक्षम हैं (http://stackoverflow.com/questions/5766208/which-is-the-right-one-nil-or-null-to-mark- कोई उद्देश्य-सी ब्लॉक)? – penfold

+6

@FransGuelinckx कृपया इस उत्तर को स्वीकार करें यदि यह आपकी समस्या का समाधान करता है। –

3

मैं अपने कोड के आधार पर इस समारोह बना दिया:

- (void)flipCurrentView:(UIView*)oldView withNewView:(UIView*)newView reverse:(BOOL)reverse 
{ 
    newView.alpha = 0; 
    [UIView transitionWithView:newView 
         duration:1  
         options:UIViewAnimationOptionTransitionFlipFromLeft 
        animations:^{   
         oldView.alpha = 0; 
         newView.alpha = 1; 
        } 
        completion:^(BOOL finished){ 
         if(reverse){ 
          [self flipCurrentView:newView withNewView:oldView reverse:NO]; 
         } 
         finished = YES; 
        }]; 
} 
संबंधित मुद्दे