Swift3.0 动画(缩放、晃动、翻转)
来源:互联网 发布:淘宝注册用户 编辑:程序博客网 时间:2024/04/30 05:22
Swift3.0写--2.左右晃动
func shakeAnimation(){//移除self.mineTopView.layer上的所有动画,可以避免多次重复添加self.mineTopView.layer.removeAllAnimations() let momAnimation = CABasicAnimation(keyPath: "transform.rotation.z") momAnimation.fromValue = NSNumber(value: -0.1) //左幅度 momAnimation.toValue = NSNumber(value: 0.1) //右幅度 momAnimation.duration = 0.1 momAnimation.repeatCount = HUGE //无限重复 momAnimation.autoreverses = true //动画结束时执行逆动画 self.momAnimation.isRemovedOnCompletion = false //切出此界面再回来动画不会停止 self.momAnimation.delegate = self//CAAnimationDelegate 代理中有动画的开始和结束 self.mineTopView.layer.add(momAnimation, forKey: "centerLayer") }
//旋转动画 func rorateAnimation(holdView: UIView){ let momAnimation = CABasicAnimation(keyPath: "transform.rotation.z") momAnimation.fromValue = NSNumber(value: 0) //左幅度 momAnimation.toValue = NSNumber(value: M_PI*2) //右幅度 momAnimation.duration = 1 momAnimation.repeatCount = HUGE //无限重复 holdView.layer.add(momAnimation, forKey: "centerLayer") }
1.缩放
- (void)Animation{ // 设定为缩放 CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.scale"]; // 动画选项设定 animation.duration = 2.0; // 动画持续时间 animation.repeatCount = HUGE_VALF; // 重复次数(无限) animation.autoreverses = YES; // 动画结束时执行逆动画 // 缩放倍数 animation.fromValue = [NSNumber numberWithFloat:0.9]; // 开始时的倍率 animation.toValue = [NSNumber numberWithFloat:1.1]; // 结束时的倍率 // 添加动画 [self.moveView.layer addAnimation:animation forKey:@"scale-layer"];}
2.左右晃动
- (void)animation{ //z轴 CABasicAnimation *momAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"]; momAnimation.fromValue = [NSNumber numberWithFloat:-0.1];//左幅度 momAnimation.toValue = [NSNumber numberWithFloat:0.1];//右幅度 momAnimation.duration = 1.5; momAnimation.repeatCount = CGFLOAT_MAX;//无限重复 momAnimation.autoreverses = YES;//动画结束时执行逆动画 momAnimation.delegate = self; [self.moveView.layer addAnimation:momAnimation forKey:@"centerLayer"]; }
3.翻转动画
- (void)transitionAnimation{ CGContextRef context=UIGraphicsGetCurrentContext(); [UIView beginAnimations:nil context:context]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];//可选 [UIView setAnimationDuration:1.0]; [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.moveView cache:YES];//UIViewAnimationTransitionCurlUp五种翻转效果可选 [UIView setAnimationDelegate:self]; [UIView commitAnimations];}
4.循环动画
[UIView animateWithDuration:timer animations:^{ //执行 } completion:^(BOOL finished) { //结束后再执行(就是不知无限循环有多大危害) }];
0 5
- Swift3.0 动画(缩放、晃动、翻转)
- 左右晃动的动画
- 晃动动画加震动
- Swift3.0转场动画的使用
- 自定义转场动画--Swift3.0版本
- iOS Swift3.0 UIView动画详解
- 自定义转场动画--Swift3.0版本
- swift3.0 图片放大缩小动画效果
- UIAccelerometer--晃动手机播放动画
- iOS 视图左右晃动动画
- 删除app动画效果,晃动动画
- 翻转动画
- 动画翻转
- UIView翻转和缩放
- UIView翻转和缩放
- UIView的,翻转、旋转,偏移,翻页,缩放,取反的动画效果
- 风火轮 –动画效果:擦除、形状、轮子、随机线条、翻转远近、缩放、旋转、弹跳效果
- 关于CABasicAnimation —实现简单的滚动、平移、翻转、缩放动画
- 数据库分词查询的优缺点以及英文和中文各自的分词方法(二)
- MySQL添加用户、删除用户与授权
- 自定义控件----方向盘的基本实现
- undefined reference to 'socket' 错误
- Android之获取应用程序(包)的大小-----PackageManager的使用(二)
- Swift3.0 动画(缩放、晃动、翻转)
- ReadLine & Read
- 为学
- Scroller的使用
- HDU 2612 Find a way (BFS+dp)
- 无需Flash录视频——HTML5中级进阶
- keras神经网络常见问题-mse, nmse
- linux hard link和soft link(硬链接和软链接)的简单介绍
- swift:懒加载控件