5

मैं एक बहुत ही सरल कार्य से फंस गया हूं, मैं एक UIView एनीमेशन को आसानी से/आसानी से करना चाहता हूं लेकिन यह सही एनीमेशन विकल्प का उपयोग करने के बावजूद हमेशा रैखिक है।UIView एनीमेशन वक्र आसानी से काम नहीं कर रहा है

यहां कोड है जो सभी खातों द्वारा काम करना चाहिए, यह एक UIViewControllerAnimatedTransitioning क्लास में सेट है लेकिन मेरे पास पिछले कस्टम सेग्यू क्लास में एक ही समस्या है;

[UIView animateWithDuration:0.4f delay:0.0f options:UIViewAnimationOptionCurveEaseInOut animations:^(void) { 

     self.dimView.alpha = 1.0; 
     self.imageView.frame = self.destinationRect; 

    } completion:^(BOOL finished) { 

     [self.imageView removeFromSuperview]; 
     [self.dimView removeFromSuperview]; 

     [transitionContext completeTransition:YES]; 

    }]; 

हालांकि, निम्न कोड के साथ एक वसंत एनीमेशन काम करता है हालांकि मैं ऐसा नहीं करता।

[UIView animateWithDuration:0.8f delay:0 usingSpringWithDamping:0.7f initialSpringVelocity:2.0f options:UIViewAnimationOptionCurveEaseInOut animations:^(void) { 

     self.dimView.alpha = 1.0; 
     self.imageView.frame = self.destinationRect; 

    } completion:^(BOOL finished){ 

     [self.imageView removeFromSuperview]; 
     [self.dimView removeFromSuperview]; 

     [transitionContext completeTransition:YES]; 

    }]; 

मुझे सिम्युलेटर और आईपैड 2 परीक्षण डिवाइस पर एक ही व्यवहार मिल रहा है। क्या मैं कुछ गलत कर रहा हूं? क्या फ्रेम या अल्फा मान एनिमेट करने में कोई समस्या है?

उत्तर

3

आप इस instead.-

[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationBeginsFromCurrentState:YES]; 
[UIView setAnimationDuration:0.4f]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
[UIView setAnimationDelegate:self]; 
[UIView setAnimationDidStopSelector:@selector(animationDidStop)]; 

self.dimView.alpha = 1.0; 
self.imageView.frame = self.destinationRect; 

[UIView commitAnimations]; 

- (void) animationDidStop { 
    [self.imageView removeFromSuperview]; 
    [self.dimView removeFromSuperview]; 
    [transitionContext completeTransition:YES]; 
} 

आशा है कि यह मदद करता है की कोशिश कर सकते।

:

+0

धन्यवाद ssantos। पहले मैंने सोचा कि यह चाल है लेकिन मेरी आंखें मुझे बेवकूफ़ बना रही थीं। अभी भी निश्चित रूप से रैखिक। बहुत अजीब और कष्टप्रद। –

+0

एमएमएच वास्तव में अजीब, अंतर को ध्यान में रखने के लिए दूरी बहुत छोटी हो सकती है? मैं सिर्फ 'एनीमेशन' के साथ 'बड़ी' एनीमेशन की कोशिश करता हूं। – ssantos

1

आप निम्न का उपयोग कर सकते [आत्म संक्रमण: छोड़ दिया]; // कॉल के रूप में आवश्यक

enum animationFrom { 
    top, 
    bottom, 
    left, 
    right 
}; 

- (void)transition:(NSUInteger)index { 
    CATransition *tr=[CATransition animation]; 
    tr.duration=0.45; 
    tr.timingFunction=[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
    tr.type=kCATransitionPush; 
    tr.delegate=self; 
    switch (index) { 
     case top: 
      tr.subtype=kCATransitionFromBottom; 
      break; 
     case bottom: 
      tr.subtype=kCATransitionFromTop; 
      break; 
     case left: 
      tr.subtype=kCATransitionFromRight; 
      break; 
     case right: 
      tr.subtype=kCATransitionFromLeft; 
      break; 
     default: 
      break; 
    } 
    [self.view.layer addAnimation:tr forKey:nil]; 
} 
1

डिफ़ॉल्ट एनीमेशन वक्र विकल्प UIViewAnimationOptionCurveEaseInOut है, तो आप इस एक निर्दिष्ट करने की आवश्यकता नहीं है। यह UIViewAnimationOptionCurveLinear है जिसे आपको स्पष्ट होना है।

क्या आप सुनिश्चित हैं कि आपका एनीमेशन वक्र रैखिक है? एनीमेशन अवधि कुछ सेकंड में सेट के साथ, दो विचारों को साइड साइड एनिमेट करने का प्रयास करें।

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