2012-06-11 4 views
11

क्या चीजों को "छोटा और आसान" तरीका नीचे करने का कोई तरीका है? वक्र अभी भी EaseOut का उपयोग करता प्रतीत होता है।आईओएस UIView एनीमेशन घटता

[UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 
[UIView animateWithDuration:0.5 animations:^{ 
    // ... do stuff here 
}]; 

उत्तर

25

आप दो अलग-अलग प्रकार के UIView-एनिमेशन को मिश्रित कर रहे हैं। आपको इनमें से कुछ का उपयोग करना चाहिए:

[UIView animateWithDuration:0.5 
         delay:0.0 
        options:UIViewAnimationOptionCurveEaseIn 
       animations:^{ 
        // ... do stuff here 
       } completion:NULL]; 

यह नए ब्लॉक-आधारित UIView-एनीमेशन API से आया था।

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:0.5]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 
// ... do stuff here 
[UIView commitAnimations]; 

वे एक ही बात करते हैं और हालांकि एप्पल के बाद से ब्लॉक आधारित API सिफारिश की गई है आप उपयोग कर सकते हैं (: पहली पंक्ति, दूसरे हाथ पर, बड़े UIView एनीमेशन एपीआई का हिस्सा है कि इस तरह दिखता है है एनीमेशन खत्म होने के बाद कॉलबैक करने के लिए आसान/क्लीनर है)।

2

आप वक्र बिंदुओं को परिभाषित करने के लिए कोर एनीमेशन, CAKeyFrameAnimation का उपयोग करके इसे कर सकते हैं। इस ट्यूटोरियल देखें: http://nachbaur.com/blog/core-animation-part-4

+4

ध्यान दें कि कड़ी केवल जवाब इतने पर यहाँ हतोत्साहित किया जाता है। कृपया [अपने उत्तर को संपादित करें] पर विचार करें (http://meta.stackexchange.com/a/8259/186599) और यहां एक सारांश जोड़ना। – NAZIK

+0

@NAZIK आपका सम्मान मैं प्रश्न का उत्तर देने और क्वेरी के लिए उचित समाधान खोजने के लिए यहां हूं! – Steve

+0

मैं ट्यूटोरियल के माध्यम से चला गया है, मेरा अपवित्र ले लो – NAZIK

0

की वक्र अंक P1, P2, P3, P4 और पी 5, ले & आसन्न अंक की एक जोड़ी के लिए मध्य बिंदु खोजते हैं। पी 1 और पी 2 के लिए मध्य बिंदु के रूप में लेबल एम 1। इसी प्रकार एम 2, एम 3, एम 4 के लिए।

  • नियंत्रण बिंदु के रूप में पी 2 के साथ m2 को इंगित करने के लिए ट्रैक्टर वक्र जोड़ें।
  • नियंत्रण बिंदु के रूप में पी 3 के साथ m3 को इंगित करने के लिए चौकोर वक्र जोड़ें।
  • नियंत्रण बिंदु के रूप में पी 4 के साथ m4 को इंगित करने के लिए चौकोर वक्र जोड़ें।

कोड: कोड ऊपर

CGFloat screenHeight = self.view.frame.size.height; 
CGFloat screenWidth = self.view.frame.size.width; 

UIView *aniView = [[UIView alloc] initWithFrame:CGRectMake(50, screenHeight, 50, 50)]; 
[aniView setBackgroundColor:[UIColor redColor]]; 
aniView.layer.cornerRadius = 25.0; 
[self.view addSubview:aniView]; 


UIBezierPath *movePath = [UIBezierPath bezierPath]; 
[movePath moveToPoint:aniView.center]; 
[movePath addQuadCurveToPoint:CGPointMake(screenWidth-50,screenHeight-50) 
       controlPoint:CGPointMake(screenWidth/2,screenHeight-150)]; 
CAKeyframeAnimation *moveAnim = [CAKeyframeAnimation animationWithKeyPath:@"position"]; 
moveAnim.path = movePath.CGPath; 
moveAnim.removedOnCompletion = YES; 
CAAnimationGroup *animGroup = [CAAnimationGroup animation]; 
animGroup.animations = [NSArray arrayWithObjects:moveAnim, nil]; 
animGroup.duration = 2.0; 

[CATransaction begin]; { 
    [CATransaction setCompletionBlock:^{ 
     [aniView.layer removeAllAnimations]; 
     [aniView removeFromSuperview]; 
    }]; 

    [aniView.layer addAnimation:animGroup forKey:nil]; 

} [CATransaction commit]; 

कॉपी पिछले कुछ विधि में और विधि कॉल करने का प्रयास ...