사용자가 다른보기를 탐색하고 휠이 다음 색상으로 회전 할 때마다 움직이는 색상환을 만들었습니다. 각 뷰에는 탐색 버튼, 사운드 버튼 및 그림 등이로드됩니다.CABasicAnimation, rotation, major slowdown
애니메이션이 호출 될 때마다 이미지가 백그라운드에 남아있어 결국 애니메이션이 크게 느려지는 것을 제외하면 모든 것이 잘 작동합니다.
매번 약 1.8 초가 소요되며 사용되는 이미지는 800x800이며 약 320x400은 한 번에 볼 수 있습니다.
내가 이해할 수있는 것으로부터, 애니메이션이 끝나면 릴리스되지 않습니다. removeFromSuperview 시도했는데 그 다음 번에 내가 사라진 다음보기로 이동하는 것을 의미합니다.
코드는 다음과 같습니다. 각각 8 개의 화면이 있으며, 각각 뒤로 이동하고 다음 버튼으로 이동합니다. 첫 번째보기에는 완벽하게 작동하는 완전 회전 컬러 휠과 시작 버튼이 표시됩니다.
#import "FlipsideView1.h"
#import "Flip1View1.h"
#import "Flip1View2.h"
#import "Flip1View3.h"
#import "Flip1View4.h"
#import "Flip1View5.h"
#import "Flip1View6.h"
#import "Flip1View7.h"
#import "Flip1View8.h"
@implementation FlipsideView1
-(void)awakeFromNib
{
[self addSubview:flip1View1];
[self performSelector:@selector(removeRainbowAnimation0) withObject:nil afterDelay:0.05];
}
- (void) removeRainbowAnimation0 {
UIImage *image = [UIImage imageNamed:@"Rainbow310.png"];
UIImageView *imgView1 =[[UIImageView alloc] initWithImage:image];
[imgView1 setFrame:(CGRect){{0,0},image.size}];
[imgView1 setCenter:(CGPoint){160,220}];
[flip1View1 addSubview:imgView1];
[imgView1 release];
CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = [NSNumber numberWithFloat:0];
fullRotation.toValue = [NSNumber numberWithFloat:((360*M_PI)/180)];
fullRotation.duration = 7;
fullRotation.repeatCount = 1e100f;
fullRotation.removedOnCompletion = YES;
[imgView1.layer addAnimation:fullRotation forKey:@"360"];
}
-(void)flip1View2
{
[flip1View1 removeFromSuperview];
[self addSubview:flip1View2];
UIImage *image = [UIImage imageNamed:@"Rainbow10.png"];
UIImageView *imgView2 =[[UIImageView alloc] initWithImage:image];
[imgView2 setFrame:(CGRect){{0,0},image.size}];
[imgView2 setCenter:(CGPoint){160,40}];
imgView2.transform = CGAffineTransformMakeRotation(1.73);
[self insertSubview:imgView2 belowSubview:flip1View2];
[imgView2 release];
}
-(void)flip1View2return
{
[flip1View2 removeFromSuperview];
[self addSubview:flip1View1];
}
-(void)flip1View3
{
[flip1View2 removeFromSuperview];
UIImage *image = [UIImage imageNamed:@"Rainbow10.png"];
UIImageView *imgView3 =[[UIImageView alloc] initWithImage:image];
[imgView3 setFrame:(CGRect){{0,0},image.size}];
[imgView3 setCenter:(CGPoint){160,40}];
[self addSubview:imgView3];
[imgView3 release];
CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = [NSNumber numberWithFloat:1.73];
fullRotation.toValue = [NSNumber numberWithFloat:2.63];
fullRotation.duration = 1.8;
fullRotation.removedOnCompletion = YES;
[imgView3.layer addAnimation:fullRotation forKey:@"360"];
[self performSelector:@selector(removeRainbowAnimation1) withObject:nil afterDelay:1.75];
}
- (void) removeRainbowAnimation1 {
[self addSubview:flip1View3];
UIImage *image = [UIImage imageNamed:@"Rainbow10.png"];
UIImageView *imgView4 =[[UIImageView alloc] initWithImage:image];
[imgView4 setFrame:(CGRect){{0,0},image.size}];
[imgView4 setCenter:(CGPoint){160,40}];
imgView4.transform = CGAffineTransformMakeRotation(2.63);
[self insertSubview:imgView4 belowSubview:flip1View3];
[imgView4 release];
}
-(void)flip1View3return
{
[flip1View3 removeFromSuperview];
UIImage *image = [UIImage imageNamed:@"Rainbow10.png"];
UIImageView *imgView5 =[[UIImageView alloc] initWithImage:image];
[imgView5 setFrame:(CGRect){{0,0},image.size}];
[imgView5 setCenter:(CGPoint){160,40}];
[self addSubview:imgView5];
[imgView5 release];
CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = [NSNumber numberWithFloat:2.63];
fullRotation.toValue = [NSNumber numberWithFloat:1.73];
fullRotation.duration = 1.8;
fullRotation.removedOnCompletion = YES;
[imgView5.layer addAnimation:fullRotation forKey:@"360"];
[self performSelector:@selector(removeRainbowAnimation11) withObject:nil afterDelay:1.75];
}
- (void) removeRainbowAnimation11 {
[self addSubview:flip1View2];
UIImage *image = [UIImage imageNamed:@"Rainbow10.png"];
UIImageView *imgView6 =[[UIImageView alloc] initWithImage:image];
[imgView6 setFrame:(CGRect){{0,0},image.size}];
[imgView6 setCenter:(CGPoint){160,40}];
imgView6.transform = CGAffineTransformMakeRotation(1.73);
[self insertSubview:imgView6 belowSubview:flip1View2];
[imgView6 release];
}
-(void)flip1View4
{
[flip1View3 removeFromSuperview];
UIImage *image = [UIImage imageNamed:@"Rainbow10.png"];
UIImageView *imgView7 =[[UIImageView alloc] initWithImage:image];
[imgView7 setFrame:(CGRect){{0,0},image.size}];
[imgView7 setCenter:(CGPoint){160,40}];
[self addSubview:imgView7];
[imgView7 release];
CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = [NSNumber numberWithFloat:2.63];
fullRotation.toValue = [NSNumber numberWithFloat:3.53];
fullRotation.duration = 1.8;
fullRotation.removedOnCompletion = YES;
[imgView7.layer addAnimation:fullRotation forKey:@"360"];
[self performSelector:@selector(removeRainbowAnimation2) withObject:nil afterDelay:1.75];
}
- (void) removeRainbowAnimation2 {
[self addSubview:flip1View4];
UIImage *image = [UIImage imageNamed:@"Rainbow10.png"];
UIImageView *imgView8 =[[UIImageView alloc] initWithImage:image];
[imgView8 setFrame:(CGRect){{0,0},image.size}];
[imgView8 setCenter:(CGPoint){160,40}];
imgView8.transform = CGAffineTransformMakeRotation(3.53);
[self insertSubview:imgView8 belowSubview:flip1View4];
[imgView8 release];
}
-(void)flip1View4return
{
[flip1View4 removeFromSuperview];
UIImage *image = [UIImage imageNamed:@"Rainbow10.png"];
UIImageView *imgView9 =[[UIImageView alloc] initWithImage:image];
[imgView9 setFrame:(CGRect){{0,0},image.size}];
[imgView9 setCenter:(CGPoint){160,40}];
[self addSubview:imgView9];
[imgView9 release];
CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = [NSNumber numberWithFloat:3.53];
fullRotation.toValue = [NSNumber numberWithFloat:2.63];
fullRotation.duration = 1.8;
fullRotation.removedOnCompletion = YES;
[imgView9.layer addAnimation:fullRotation forKey:@"360"];
[self performSelector:@selector(removeRainbowAnimation22) withObject:nil afterDelay:1.75];
}
- (void) removeRainbowAnimation22 {
[self addSubview:flip1View3];
UIImage *image = [UIImage imageNamed:@"Rainbow10.png"];
UIImageView *imgView10 =[[UIImageView alloc] initWithImage:image];
[imgView10 setFrame:(CGRect){{0,0},image.size}];
[imgView10 setCenter:(CGPoint){160,40}];
imgView10.transform = CGAffineTransformMakeRotation(2.63);
[self insertSubview:imgView10 belowSubview:flip1View3];
[imgView10 release];
}
-(void)flip1View5
{
[flip1View4 removeFromSuperview];
UIImage *image = [UIImage imageNamed:@"Rainbow10.png"];
UIImageView *imgView11 =[[UIImageView alloc] initWithImage:image];
[imgView11 setFrame:(CGRect){{0,0},image.size}];
[imgView11 setCenter:(CGPoint){160,40}];
[self addSubview:imgView11];
[imgView11 release];
CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = [NSNumber numberWithFloat:3.53];
fullRotation.toValue = [NSNumber numberWithFloat:4.43];
fullRotation.duration = 1.8;
fullRotation.removedOnCompletion = YES;
[imgView11.layer addAnimation:fullRotation forKey:@"360"];
[self performSelector:@selector(removeRainbowAnimation3) withObject:nil afterDelay:1.75];
}
- (void) removeRainbowAnimation3 {
[self addSubview:flip1View5];
UIImage *image = [UIImage imageNamed:@"Rainbow10.png"];
UIImageView *imgView12 =[[UIImageView alloc] initWithImage:image];
[imgView12 setFrame:(CGRect){{0,0},image.size}];
[imgView12 setCenter:(CGPoint){160,40}];
imgView12.transform = CGAffineTransformMakeRotation(4.43);
[self insertSubview:imgView12 belowSubview:flip1View5];
[imgView12 release];
}
-(void)flip1View5return
{
[flip1View5 removeFromSuperview];
UIImage *image = [UIImage imageNamed:@"Rainbow10.png"];
UIImageView *imgView13 =[[UIImageView alloc] initWithImage:image];
[imgView13 setFrame:(CGRect){{0,0},image.size}];
[imgView13 setCenter:(CGPoint){160,40}];
[self addSubview:imgView13];
[imgView13 release];
CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = [NSNumber numberWithFloat:4.43];
fullRotation.toValue = [NSNumber numberWithFloat:3.53];
fullRotation.duration = 1.8;
fullRotation.removedOnCompletion = YES;
[imgView13.layer addAnimation:fullRotation forKey:@"360"];
[self performSelector:@selector(removeRainbowAnimation33) withObject:nil afterDelay:1.75];
}
- (void) removeRainbowAnimation33 {
[self addSubview:flip1View4];
UIImage *image = [UIImage imageNamed:@"Rainbow10.png"];
UIImageView *imgView14 =[[UIImageView alloc] initWithImage:image];
[imgView14 setFrame:(CGRect){{0,0},image.size}];
[imgView14 setCenter:(CGPoint){160,40}];
imgView14.transform = CGAffineTransformMakeRotation(3.53);
[self insertSubview:imgView14 belowSubview:flip1View4];
[imgView14 release];
}
-(void)flip1View6
{
[flip1View5 removeFromSuperview];
UIImage *image = [UIImage imageNamed:@"Rainbow10.png"];
UIImageView *imgView15 =[[UIImageView alloc] initWithImage:image];
[imgView15 setFrame:(CGRect){{0,0},image.size}];
[imgView15 setCenter:(CGPoint){160,40}];
[self addSubview:imgView15];
[imgView15 release];
CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = [NSNumber numberWithFloat:4.43];
fullRotation.toValue = [NSNumber numberWithFloat:5.33];
fullRotation.duration = 1.8;
fullRotation.removedOnCompletion = YES;
[imgView15.layer addAnimation:fullRotation forKey:@"360"];
[self performSelector:@selector(removeRainbowAnimation4) withObject:nil afterDelay:1.75];
}
- (void) removeRainbowAnimation4 {
[self addSubview:flip1View6];
UIImage *image = [UIImage imageNamed:@"Rainbow10.png"];
UIImageView *imgView16 =[[UIImageView alloc] initWithImage:image];
[imgView16 setFrame:(CGRect){{0,0},image.size}];
[imgView16 setCenter:(CGPoint){160,40}];
imgView16.transform = CGAffineTransformMakeRotation(5.33);
[self insertSubview:imgView16 belowSubview:flip1View6];
[imgView16 release];
}
-(void)flip1View6return
{
[flip1View6 removeFromSuperview];
UIImage *image = [UIImage imageNamed:@"Rainbow10.png"];
UIImageView *imgView17 =[[UIImageView alloc] initWithImage:image];
[imgView17 setFrame:(CGRect){{0,0},image.size}];
[imgView17 setCenter:(CGPoint){160,40}];
[self addSubview:imgView17];
[imgView17 release];
CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = [NSNumber numberWithFloat:5.33];
fullRotation.toValue = [NSNumber numberWithFloat:4.43];
fullRotation.duration = 1.8;
fullRotation.removedOnCompletion = YES;
[imgView17.layer addAnimation:fullRotation forKey:@"360"];
[self performSelector:@selector(removeRainbowAnimation44) withObject:nil afterDelay:1.75];
}
- (void) removeRainbowAnimation44 {
[self addSubview:flip1View5];
UIImage *image = [UIImage imageNamed:@"Rainbow10.png"];
UIImageView *imgView18 =[[UIImageView alloc] initWithImage:image];
[imgView18 setFrame:(CGRect){{0,0},image.size}];
[imgView18 setCenter:(CGPoint){160,40}];
imgView18.transform = CGAffineTransformMakeRotation(4.43);
[self insertSubview:imgView18 belowSubview:flip1View5];
[imgView18 release];
}
-(void)flip1View7
{
[flip1View6 removeFromSuperview];
UIImage *image = [UIImage imageNamed:@"Rainbow10.png"];
UIImageView *imgView19 =[[UIImageView alloc] initWithImage:image];
[imgView19 setFrame:(CGRect){{0,0},image.size}];
[imgView19 setCenter:(CGPoint){160,40}];
[self addSubview:imgView19];
[imgView19 release];
CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = [NSNumber numberWithFloat:5.33];
fullRotation.toValue = [NSNumber numberWithFloat:6.23];
fullRotation.duration = 1.8;
fullRotation.removedOnCompletion = YES;
[imgView19.layer addAnimation:fullRotation forKey:@"360"];
[self performSelector:@selector(removeRainbowAnimation5) withObject:nil afterDelay:1.75];
}
- (void) removeRainbowAnimation5 {
[self addSubview:flip1View7];
UIImage *image = [UIImage imageNamed:@"Rainbow10.png"];
UIImageView *imgView20 =[[UIImageView alloc] initWithImage:image];
[imgView20 setFrame:(CGRect){{0,0},image.size}];
[imgView20 setCenter:(CGPoint){160,40}];
imgView20.transform = CGAffineTransformMakeRotation(6.23);
[self insertSubview:imgView20 belowSubview:flip1View7];
[imgView20 release];
}
-(void)flip1View7return
{
[flip1View7 removeFromSuperview];
UIImage *image = [UIImage imageNamed:@"Rainbow10.png"];
UIImageView *imgView21 =[[UIImageView alloc] initWithImage:image];
[imgView21 setFrame:(CGRect){{0,0},image.size}];
[imgView21 setCenter:(CGPoint){160,40}];
[self addSubview:imgView21];
[imgView21 release];
CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = [NSNumber numberWithFloat:6.23];
fullRotation.toValue = [NSNumber numberWithFloat:5.33];
fullRotation.duration = 1.8;
fullRotation.removedOnCompletion = YES;
[imgView21.layer addAnimation:fullRotation forKey:@"360"];
[self performSelector:@selector(removeRainbowAnimation55) withObject:nil afterDelay:1.75];
}
- (void) removeRainbowAnimation55 {
[self addSubview:flip1View6];
UIImage *image = [UIImage imageNamed:@"Rainbow10.png"];
UIImageView *imgView22 =[[UIImageView alloc] initWithImage:image];
[imgView22 setFrame:(CGRect){{0,0},image.size}];
[imgView22 setCenter:(CGPoint){160,40}];
imgView22.transform = CGAffineTransformMakeRotation(5.33);
[self insertSubview:imgView22 belowSubview:flip1View6];
[imgView22 release];
}
-(void)flip1View8
{
[flip1View7 removeFromSuperview];
UIImage *image = [UIImage imageNamed:@"Rainbow10.png"];
UIImageView *imgView23 =[[UIImageView alloc] initWithImage:image];
[imgView23 setFrame:(CGRect){{0,0},image.size}];
[imgView23 setCenter:(CGPoint){160,40}];
[self addSubview:imgView23];
[imgView23 release];
CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = [NSNumber numberWithFloat:6.23];
fullRotation.toValue = [NSNumber numberWithFloat:7.13];
fullRotation.duration = 1.8;
fullRotation.removedOnCompletion = YES;
[imgView23.layer addAnimation:fullRotation forKey:@"360"];
[self performSelector:@selector(removeRainbowAnimation6) withObject:nil afterDelay:1.75];
}
- (void) removeRainbowAnimation6 {
[self addSubview:flip1View8];
UIImage *image = [UIImage imageNamed:@"Rainbow10.png"];
UIImageView *imgView24 =[[UIImageView alloc] initWithImage:image];
[imgView24 setFrame:(CGRect){{0,0},image.size}];
[imgView24 setCenter:(CGPoint){160,40}];
imgView24.transform = CGAffineTransformMakeRotation(7.13);
[self insertSubview:imgView24 belowSubview:flip1View8];
[imgView24 release];
}
-(void)flip1View8return
{
[flip1View8 removeFromSuperview];
UIImage *image = [UIImage imageNamed:@"Rainbow10.png"];
UIImageView *imgView25 =[[UIImageView alloc] initWithImage:image];
[imgView25 setFrame:(CGRect){{0,0},image.size}];
[imgView25 setCenter:(CGPoint){160,40}];
[self addSubview:imgView25];
[imgView25 release];
CABasicAnimation *fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
fullRotation.fromValue = [NSNumber numberWithFloat:7.13];
fullRotation.toValue = [NSNumber numberWithFloat:6.23];
fullRotation.duration = 1.8;
fullRotation.removedOnCompletion = YES;
[imgView25.layer addAnimation:fullRotation forKey:@"360"];
[self performSelector:@selector(removeRainbowAnimation66) withObject:nil afterDelay:1.75];
}
- (void) removeRainbowAnimation66 {
[self addSubview:flip1View7];
UIImage *image = [UIImage imageNamed:@"Rainbow10.png"];
UIImageView *imgView26 =[[UIImageView alloc] initWithImage:image];
[imgView26 setFrame:(CGRect){{0,0},image.size}];
[imgView26 setCenter:(CGPoint){160,40}];
imgView26.transform = CGAffineTransformMakeRotation(6.23);
[self insertSubview:imgView26 belowSubview:flip1View7];
[imgView26 release];
}
-(void)flip1View8home
{
[flip1View8 removeFromSuperview];
[self addSubview:flip1View1];
}
- (void)dealloc {
[super dealloc];
}
@end
내 전체 .m입니다.
이것은 모두 사용자가 시작 화면에서 네 가지 옵션 중 하나를 선택하면 발생합니다.
감사합니다. 다시 방출 적없이 모든 방법
알렉스
에
Build -> Build and Analyse
로 이동하여당신은 누수를 확인할 수 있습니다처럼 스스로를 해제 : 당신은 할 수 있습니다. [imgView release]를 추가하는 것은 아무 것도하지 않는 것처럼 보였습니다. 또한 모든 imgView를 고유 한 이름으로 변경했습니다. –
다음과 같이 사용해야합니까? [UIView beginAnimations : nil context : NULL]; 각 방법에서? –
시간이 지남에 따라 애니메이션이 지워지지 않도록 애니메이션을 지우는 방법이 있어야합니까? 애니메이션이 전환 애니메이션 (예 : pagecurlup)을 대체한다고 생각합니다. 내비게이션을 만질 때마다 다른 애니메이션을 재생하는 대신 내 자신의 전환을 만드는 데 집중해야합니까? 나는 여기를 잃고있다. –