2012-09-06 13 views
11

में कनवर्ट करना मैं एक एनीमेशन करने की कोशिश कर रहा हूं जहां मैं एक सीजीपॉइंट को एक दृश्य से दूसरे स्थान पर ले जाता हूं, मैं निर्देशांक ढूंढना चाहता हूं जहां बिंदु संदर्भ में होगा सबसे पहले मैं एनीमेशन कर सकता हूँ।एक दृश्य से दूसरे दृश्य में सीजी पॉइंट्स को एक एनीमेशन

तो मान लें कि मेरे पास एक बिंदु (24,15) दृश्य 2 है और मैं इसे देखने के लिए एनिमेट करना चाहता हूं, मैं अभी भी बिंदु को जोड़ रहा हूं क्योंकि मैं बिंदु जोड़ रहा हूं नए दृश्य के सबव्यू के रूप में, लेकिन एनीमेशन के लिए मुझे उस बिंदु के बारे में जानने की आवश्यकता है जहां बिंदु होगा ताकि मैं एक ट्विन कर सकूं।

इस ग्राफ को देखें:

enter image description here

अब इस मुझे क्या करना कोशिश कर रहा हूँ है:

customObject *lastAction = [undoStack pop]; 
customDotView *aDot = lastAction.dot; 
CGPoint oldPoint = aDot.center; 
CGPoint newPoint = lastAction.point; 

newPoint = [lastAction.view convertPoint:newPoint toView:aDot.superview]; 


CABasicAnimation *anim4 = [CABasicAnimation animationWithKeyPath:@"position"]; 
anim4.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; 
anim4.fromValue = [NSValue valueWithCGPoint:CGPointMake(oldPoint.x, oldPoint.y)]; 
anim4.toValue = [NSValue valueWithCGPoint:CGPointMake(newPoint.x, newPoint.y)]; 
anim4.repeatCount = 0; 
anim4.duration = 0.1; 
[aDot.layer addAnimation:anim4 forKey:@"position"]; 


[aDot removeFromSuperview]; 


[lastAction.view addSubview:aDot]; 
[lastAction.view bringSubviewToFront:aDot]; 

aDot.center = newPoint; 

कोई भी विचार?

+0

क्या दोनों विचार प्रदर्शन में दिखाई दे रहे हैं? जैसा कि वे एक बड़े दृश्य में निहित हैं? –

उत्तर

8

ब्लॉक एनिमेशन के साथ देखना आसान है। मुझे लगता है कि इसका उद्देश्य इसकी समन्वय स्थान में व्यू 2 सबव्यूव की एनीमेशन करना है, फिर, जब एनीमेशन समाप्त हो जाए, तो नए समन्वय स्थान में परिवर्तित होने वाली अंतिम स्थिति का उपयोग करके 1 देखने के लिए एक सबव्यू जोड़ें।

// assume we have a subview of view2 called UIView *dot; 
// assume we want to move it by some vector relative to it's initial position 
// call that CGPoint offset; 

// compute the end point in view2 coords, that's where we'll do the animation 
CGPoint endPointV2 = CGPointMake(dot.center.x + offset.x, dot.center.y + offset.y); 

// compute the end point in view1 coords, that's where we'll want to add it in view1 
CGPoint endPointV1 = [view2 convertPoint:endPointV2 toView:view1]; 

[UIView animateWithDuration:1.0 animations:^{ 
    dot.center = endPointV2; 
} completion:^(BOOL finished) { 
    dot.center = endPointV1; 
    [view1 addSubview:dot]; 
}]; 

ध्यान दें कि देखने के लिए डॉट जोड़ना 1 इसे दृश्य 2 से हटा देता है। यह भी ध्यान रखें कि अगर दृश्य 1 clipsToBounds == NO होना चाहिए यदि ऑफसेट वेक्टर इसके बाउंड के बाहर बिंदु को स्थानांतरित करता है।

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