2012-02-07 12 views
6

तो, मैं 7.परत स्थिति की (कोर) एनीमेशन शुरू में कूदता

अब तक मैं है निम्नलिखित कोड है, लेकिन मैं के एक जोड़े है, एक टाइल flipping प्रभाव पैदा करने के लिए कोशिश कर रहा हूँ विंडोज फोन पर की तरह प्रश्नों।

CALayer *layer = self.theRedSquare.layer; 
CATransform3D initialTransform = self.theRedSquare.layer.transform; 
initialTransform.m34 = 1.0/-1000; 

[UIView beginAnimations:@"Scale" context:nil]; 
[UIView setAnimationDuration:1]; 
[UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; 
layer.transform = initialTransform; 
layer.anchorPoint = CGPointMake(-0.3, 0.5); 

CATransform3D rotationAndPerspectiveTransform = self.theRedSquare.layer.transform; 

rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, M_PI , 0 , -self.theRedSquare.bounds.size.height/2, 0); 

layer.transform = rotationAndPerspectiveTransform; 

[UIView setAnimationDelegate:self]; 
[UIView commitAnimations]; 

1. कैसे मेरी मेरी लाल चौक (एक सरल यूआई देखें) आ एनीमेशन के शुरू में सही करने के लिए अनुवाद?

2. एंकर पॉइंट के लिए पैरेंट व्यू पर स्थिति निर्धारित करना संभव है? फिलहाल मैं मनमाने ढंग से वर्तमान दृश्य के सापेक्ष इसे स्थापित कर रहा हूं।

किसी भी पॉइंटर्स के लिए अग्रिम धन्यवाद।

एनीमेशन

Before

एनीमेशन के दौरान इससे पहले कि (वर्ग नोटिस सही हो गया है)

During

एनीमेशन के बाद (नोटिस वर्ग सही हो गया है)

After

वीडियो कहा: example video

उत्तर

6
-(void)setAnchorPoint:(CGPoint)anchorPoint forView:(UIView *)view 
{ 
    CGPoint newPoint = CGPointMake(view.bounds.size.width * anchorPoint.x, view.bounds.size.height * anchorPoint.y); 
    CGPoint oldPoint = CGPointMake(view.bounds.size.width * view.layer.anchorPoint.x, view.bounds.size.height * view.layer.anchorPoint.y); 

    newPoint = CGPointApplyAffineTransform(newPoint, view.transform); 
    oldPoint = CGPointApplyAffineTransform(oldPoint, view.transform); 

    CGPoint position = view.layer.position; 

    position.x -= oldPoint.x; 
    position.x += newPoint.x; 

    position.y -= oldPoint.y; 
    position.y += newPoint.y; 

    view.layer.position = position; 
    view.layer.anchorPoint = anchorPoint; 
} 

-(void)animateView:(UIView *)theRedSquare 
{ 
    CALayer *layer = theRedSquare.layer; 
    CATransform3D initialTransform = theRedSquare.layer.transform; 
    initialTransform.m34 = 1.0/-1000; 

    [self setAnchorPoint:CGPointMake(-0.3, 0.5) forView:theRedSquare]; 


    [UIView beginAnimations:@"Scale" context:nil]; 
    [UIView setAnimationDuration:1]; 
    [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut]; 
    layer.transform = initialTransform; 


    CATransform3D rotationAndPerspectiveTransform = theRedSquare.layer.transform; 

    rotationAndPerspectiveTransform = CATransform3DRotate(rotationAndPerspectiveTransform, M_PI , 0 , -theRedSquare.bounds.size.height/2, 0); 

    layer.transform = rotationAndPerspectiveTransform; 

    [UIView setAnimationDelegate:self]; 
    [UIView commitAnimations]; 
} 

इस से लिया, और थोड़ा बदलाव किया .. उम्मीद है कि यह Changing my CALayer's anchorPoint moves the view

+0

शानदार, धन्यवाद! – JonB

+0

एनीमेशन को केवल एनिमेट करने के लिए आप कैसे प्राप्त करते हैं? (उस फ्लिप में) मैं इसे समझने के लिए घंटों तक कोशिश कर रहा हूं। – Frankrockz

2

एक CALayer की anchorPoint की स्वीकार्य सीमा है [0,1]। आपके मामले में, जहां आप वाई अक्ष के चारों ओर फ़्लिप करने का प्रयास कर रहे हैं, तो आपकी परत का एंकर पॉइंट [0, 0.5] होना चाहिए।

+0

मैं इस काम कर ठीक किया था मदद करता है , लेकिन एनीमेशन शुरू करने से पहले लाल UIView ठीक से बदल जाता है। मैं कोशिश करूंगा और एक वीडियो प्राप्त करूंगा। दिलचस्प बात यह है कि एंकरपॉइंट कामों के लिए -0.3, यह वाई-अक्ष ऑफ़सेट के आसपास बाईं ओर घूमता है। – JonB

+0

ने समस्या दिखाने के लिए एक वीडियो जोड़ा है। एनीमेशन के पहले भाग पर वर्ग स्क्वायर को कई पिक्सेल बदल देता है। इसे काम करने के लिए प्रतीत नहीं कर सकते हैं। – JonB

3

आप वर्ग का अपना दृश्य बनाते हैं, तो flipping अंतर्निहित है

[UIView beginAnimations:@"flip" context:nil]; 
[UIView setAnimationDuration:.35f]; 
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn]; 
[UIView setAnimationTransition: UIViewAnimationTransitionFlipFromLeft 
    forView:self.window cache:YES]; 

// change to the new view (make this one hidden, the other not) 

[UIView commitAnimations]; 
+0

मुझे सराहना है कि यह मेरे विवरण से अत्यधिक स्पष्ट नहीं था, लेकिन मैं स्पॉट से फ़्लिप करने के बाद नहीं हूं। मैं अपने लाल वर्ग के बाएं हाथ के किनारे के चारों ओर फ़्लिप करना चाहता हूं (जो पहले से ही एक UIView है)। निम्न वीडियो देखें जिसके बाद मैं प्रभाव डाल रहा हूं: http://www.youtube.com/watch?v=wgoGDPF_NGo – JonB

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