动画无限循环播放问题

UIView beginAnimations:nil context:NULL];

UIView setAnimationDuration:5.0f];

self.transform=CGAffineTransformMakeRotation(M_PI);

UIView commitAnimations];

如何让这个动画循环播放,我要的是无限循环。xie x ie

UIView.animationRepeatCount =HUGE_VALF;



不好意思,这个方法不行

看看我写的,哈哈

static int i = 1;

- (void)viewDidLoad

{

self.temp = UIView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];

self.temp.backgroundColor = UIColor blackColor];

self.view addSubview:_temp];

NSTimer * splashTimer = nil;

splashTimer = NSTimer scheduledTimerWithTimeInterval:5.0 target:selfselector:@selector(rote) userInfo:nil repeats:YES];

super viewDidLoad];

}

-(void)rote

{

UIView beginAnimations:nil context:NULL];

UIView setAnimationDuration:5.0f];

self.temp.transform=CGAffineTransformMakeRotation(M_PI_2 * i);

i++;

UIView commitAnimations];

}


之所以不转了是因为角度没有变化,所以停止转动了,不停的改变 transform的角度也是可以的

嗯,谢谢,辛苦了。我觉得还是设置一个无限大的数比较好。

- (void)viewDidLoad

{

self.temp = UIView alloc]initWithFrame:CGRectMake(100, 100, 200, 200)];

self.temp.backgroundColor = UIColor blackColor];

self.view addSubview:_temp];

NSTimer * splashTimer = nil;

splashTimer = NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(rote) userInfo:nil repeats:YES];

super viewDidLoad];

}

-(void)rote

{

UIView beginAnimations:@"anim" context:NULL];

UIView setAnimationDuration:1.0f];

UIView setAnimationDelegate:self];

UIView setAnimationRepeatCount:0];

UIView setAnimationDidStopSelector:@selector(resetTramsform:)];

self.temp.transform=CGAffineTransformMakeRotation(M_PI_2);

UIView commitAnimations];

}

-(void)resetTramsform:(id)sender

{

self.temp.transform=CGAffineTransformMakeRotation(0);

}


哈哈,刚刚想了一会这次是无限大的,你试试,把角度调好

谢谢大哥,这个方法ok的。

CABasicAnimation* animation = CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];

animation.fromValue = NSNumber numberWithFloat:0.0f];

animation.toValue = NSNumber numberWithFloat:2 * M_PI];

animation.duration = 10.0f;

animation.repeatCount = HUGE_VALF;

self.view.layer addAnimation:animation forKey:nil];


时间可以自己设置,代码应该是最少的了

但是这个多任务的时候回程序动画就停了

不太明白,用其它方式实现的动画在这种条件下不会停止么?

就是home键退出程序后,再进程序动画就停止了。

animation.removedOnCompletion = NO;加上这句就可以了

太感谢了,就是这个。

能不能左右反复转动啊 怎么设置啊?两张图片不停地来回切换的动画

try this : UIView.animationRepeatCount =HUGE_VALF; 亲测repiat forever

try this : UIView.animationRepeatCount =HUGE_VALF; 亲测repiat forever

怎么让他想火箭那样上下循环的旋转呢??急求。。:2::2::2::2::2::2: