self.imageView =[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tara4.jpg"]]; self.imageView.frame =CGRectMake(85, 400, 200, 200); self.imageView.layer.cornerRadius =100; self.imageView.layer.masksToBounds=YES; [self.view addSubview:self.imageView];
// Duration 动画的时间间隔(double类型)[UIView animateWithDuration:3 animations:^{ // 动画内容写在block里 self.imageView.frame =CGRectMake(100, 100, 100, 75); }];使 imageView 移动到新的位置上,并且把size改为新的
[UIView animateWithDuration:5 animations:^{ self.imageView.frame =CGRectMake(30, 100, 300, 225); self.imageView.alpha =0; } completion:^(BOOL finished) { [UIView animateWithDuration:3 animations:^{ self.imageView.frame =CGRectMake(85, 400, 200, 150); self.imageView.alpha =1; }]; }];
[UIView animateWithDuration:5 delay:0.1 options:UIViewAnimationOptionRepeat animations:^{ self.imageView.frame =CGRectMake(30, 100, 300, 225); self.imageView.alpha =0; } completion:^(BOOL finished) { [UIView animateWithDuration:3 animations:^{ self.imageView.frame =CGRectMake(85, 400, 200, 150); self.imageView.alpha =1; }]; }];
[UIView animateWithDuration:5 delay:0.1 usingSpringWithDamping:0.1 initialSpringVelocity:10 options:UIViewAnimationOptionRepeat animations:^{ self.imageView.frame =CGRectMake(30, 100, 300, 225); self.imageView.alpha =0; } completion:^(BOOL finished) { [UIView animateWithDuration:3 animations:^{ self.imageView.frame =CGRectMake(85, 400, 200, 150); self.imageView.alpha =1; }]; }];
// 第二个参数:设置旋转的弧度 (π /4) self.imageView.transform =CGAffineTransformRotate(self.imageView.transform, M_PI_4);
self.imageView.transform = CGAffineTransformScale(self.imageView.transform, 0.9, 0.9);
self.imageView.transform = CGAffineTransformTranslate(self.imageView.transform, 50, 50);
CATransition *transition =[CATransition animation];设置动画种类 : cube (), rippleEffect (水波纹) suckEffect oglFlip transition.type =@"rippleEffect"; // 设置动画时长 [transition setDuration:3]; // 设置动画的重复次数 // NSIntegerMax 整数的最大值 [transition setRepeatCount:NSIntegerMax];//向imageView 上添加动画效果, 添加到imageView的layer上 [self.imageView.layer addAnimation:transition forKey:@"transistion"];
CABasicAnimation *basic =[CABasicAnimation animationWithKeyPath:@"transform.scale"]; // 对layer动画设置需要kvc的方式赋值 ,就是需要通过给定一个key,再去设置 // 动画时长 [basic setDuration:3]; // 动画执行的次数 [basic setRepeatCount:NSIntegerMax]; // 这个动画设置的是一个缩放的效果,需要给一个开始的初始值 缩放的初始倍数 basic.fromValue =[NSNumber numberWithInt:1]; // 在设置一个结束的值 缩放的结束倍数 basic.toValue = [NSNumber numberWithInt:2]; // toValue 和fromvalue 需要一个id类型的对象(需要整数类型,0.5按0算) //把动画添加到视图上 [self.imageView.layer addAnimation:basic forKey:@"basic"];
CABasicAnimation *basic =[CABasicAnimation animationWithKeyPath:@"transform.rotation"]; // 设置角度 basic.fromValue =[NSNumber numberWithInt:0.0]; basic.toValue =[NSNumber numberWithFloat: -4 *M_PI_2]; // 设置动画时长 [basic setDuration:3]; // 次数 [basic setRepeatCount:NSIntegerMax]; [self.imageView.layer addAnimation:basic forKey:@"basic"]; // 是否回到原位 [basic setAutoreverses:YES];