2010-08-07 5 views
5

आप ओपनजीएल ES का उपयोग किये बिना UIView, UIImageView या CALayer एनिमेटेड 360 डिग्री्रेस को कैसे घुमाते हैं?आप UIView, UIImageView या CALayer एनिमेटेड 360˚ को कैसे घुमाते हैं?

+3

आपको पता है कि 360˚ रोटेशन आप सटीक एक ही छवि है, है ना दे देंगे? – SteamTrout

+0

मुझे यह दुख हुआ कि मैंने इसे महसूस करने से पहले समाधान के बारे में सोचने की कोशिश करना शुरू कर दिया। – jtbandes

+0

@ स्टेम ट्राउट: केवल तभी जब आप इसे तात्कालिक होना चाहते हैं। – JeremyP

उत्तर

3

संभवतः आप एक पूर्ण 360 डिग्री के आसपास UIImage घूर्णन करने का अनुमान लगाते हैं? मेरे अनुभव में, जिस तरह से एक चक्र पूरा रोटेशन पूरा करने के लिए श्रृंखला के लिए है कई एनिमेशन एक साथ:

- (IBAction)rotate:(id)sender 
{ 
    [UIView beginAnimations:@"step1" context:NULL]; { 
     [UIView setAnimationDuration:1.0]; 
     [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; 
     [UIView setAnimationDelegate:self]; 
    [imageView.transform = CGAffineTransformMakeRotation(120 * M_PI/180); 
    } [UIView commitAnimations]; 
} 

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context 
{ 
    if ([animationID isEqualToString:@"step1"]) { 
     [UIView beginAnimations:@"step2" context:NULL]; { 
     [UIView setAnimationDuration:1.0]; 
     [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; 
     [UIView setAnimationDelegate:self]; 
     imageView.transform = CGAffineTransformMakeRotation(240 * M_PI/180); 
     } [UIView commitAnimations]; 
    } 
    else if ([animationID isEqualToString:@"step2"]) { 
     [UIView beginAnimations:@"step3" context:NULL]; { 
     [UIView setAnimationDuration:1.0]; 
     [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; 
     [UIView setAnimationDelegate:self]; 
     imageView.transform = CGAffineTransformMakeRotation(0); 
     } [UIView commitAnimations]; 
    } 
} 

मैं जगह में easeIn/easeOut वक्र (रेखीय के बजाय) छोड़ दिया है, इसलिए आप व्यक्तिगत एनिमेशन देख सकते हैं।

28
#import <QuartzCore/QuartzCore.h> 

CABasicAnimation *fullRotation; 
fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; 
fullRotation.fromValue = @(0.0); 
fullRotation.toValue = @((360.0 * M_PI)/180.0); 
fullRotation.duration = 3.5f; 
fullRotation.repeatCount = MAXFLOAT; 

[view.layer addAnimation:fullRotation forKey:@"rotation-animation"]; 

आप लंगर बिंदु यह चारों ओर घूमता को बदलना चाहते हैं तो आप क्या कर सकते हैं

CGRect frame = view.layer.frame; 
self.anchorPoint = CGPointMake(0.5, 0.5); // rotates around center 
self.frame = frame; 
संबंधित मुद्दे