iOS常用动画代码
- 使用前
- 需引入QuartzCore.framework, 并在相关文件中加入 #import "QuartzCore/QuartzCore.h"
- 定义
- shakeFeedbackOverlay为UIImageView
- 设置
- self.shakeFeedbackOverlay.alpha = 0.0;
- self.shakeFeedbackOverlay.layer.cornerRadius = 10.0; //设置圆角半径
- 、图像左右抖动
- CABasicAnimation* shake = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
- shake.fromValue = [NSNumber numberWithFloat:-M_PI/];
- shake.toValue = [NSNumber numberWithFloat:+M_PI/];
- shake.duration = 0.1;
- shake.autoreverses = YES; //是否重复
- shake.repeatCount = ;
- [self.shakeFeedbackOverlay.layer addAnimation:shake forKey:@"shakeAnimation"];
- self.shakeFeedbackOverlay.alpha = 1.0;
- [UIView animateWithDuration:2.0 delay:0.0 options:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionAllowUserInteraction animations:^{ self.shakeFeedbackOverlay.alpha = 0.0; //透明度变0则消失 } completion:nil];
- 摇晃动画2:
{
CAKeyframeAnimation *frame=[CAKeyframeAnimation animation];
CGFloat left=-M_PI_2*0.125;
CGFloat right=M_PI_2*0.125;
frame.keyPath=@"postion";
frame.keyPath=@"transform.rotation";
frame.values=@[@(left),@(right),@(left)];
frame.duration = 0.5;
frame.repeatCount = 1000000;
[cell.layer addAnimation:frame forKey:nil];
}
- 、图像顺时针旋转
- CABasicAnimation* shake = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
- shake.fromValue = [NSNumber numberWithFloat:];
- shake.toValue = [NSNumber numberWithFloat:*M_PI];
- shake.duration = 0.8; shake.autoreverses = NO;
- shake.repeatCount = ;
- [self.shakeFeedbackOverlay.layer addAnimation:shake forKey:@"shakeAnimation"];
- self.shakeFeedbackOverlay.alpha = 1.0;
- [UIView animateWithDuration:10.0 delay:0.0 options:UIViewAnimationOptionCurveEaseIn | UIViewAnimationOptionAllowUserInteraction animations:^{ self.shakeFeedbackOverlay.alpha = 0.0; } completion:nil];
- 、图像关键帧动画
- CAKeyframeAnimation *animation = [CAKeyframeAnimationanimation];
- CGMutablePathRef aPath = CGPathCreateMutable();
- CGPathMoveToPoint(aPath, nil, , );
- CGPathAddCurveToPoint(aPath, nil, , , , , , );
- animation.path = aPath;
- animation.autoreverses = YES;
- animation.duration = ;
- animation.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseOut];
- animation.rotationMode = @"auto";
- [ballView.layer addAnimation:animation forKey:@"position"];
- 、组合动画 CAAnimationGroup
- CABasicAnimation *flip = [CABasicAnimationanimationWithKeyPath:@"transform.rotation.y"];
- flip.toValue = [NSNumbernumberWithDouble:-M_PI];
- CABasicAnimation *scale= [CABasicAnimationanimationWithKeyPath:@"transform.scale"];
- scale.toValue = [NSNumbernumberWithDouble:];
- scale.duration = 1.5;
- scale.autoreverses = YES;
- CAAnimationGroup *group = [CAAnimationGroupanimation];
- group.animations = [NSArrayarrayWithObjects:flip, scale, nil];
- group.timingFunction = [CAMediaTimingFunctionfunctionWithName:kCAMediaTimingFunctionEaseInEaseOut];
- group.duration = ;
- group.fillMode = kCAFillModeForwards;
- group.removedOnCompletion = NO;
- [ballView.layer addAnimation:group forKey:@"position"];
- 、指定时间内旋转图片
- //启动定时器 旋转光圈
- - (void)startRotate
- {
- self.rotateTimer = [NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(rotateGraduation) userInfo:nil repeats:YES];
- }
- //关闭定时器
- - (void)stopTimer
- {
- if ([self.rotateTimer isValid])
- {
- [self.rotateTimer invalidate]; self.rotateTimer = nil;
- }
- }
- //旋转动画
- - (void)rotateGraduation
- {
- self.timeCount--;
- if (self.timeCount == )
- {
- [self stopTimer];
- // doSomeThing //旋转完毕 可以干点别的
- self.timeCount = ;
- }
- else
- {
- //计算角度 旋转
- static CGFloat radian = * (M_2_PI / );
- CGAffineTransform transformTmp = self.lightImageView.transform;
- transformTmp = CGAffineTransformRotate(transformTmp, radian);
- self.lightImageView.transform = transformTmp;
- };
- }
- 调用方法
- self.timeCount = ; //动画执行25次
- [self startRotate];
转载自:http://www.cnblogs.com/sell/archive/2013/02/01/2889013.html
iOS常用动画代码的更多相关文章
- IOS 制作动画代码和 设置控件透明度
方式1: //animateWithDuration用1秒钟的时间,执行代码 [UIView animateWithDuration:1.0 animations:^{ //存放需要执行的动画代码 s ...
- ios常用动画
// // CoreAnimationEffect.h // CoreAnimationEffect // // Created by VincentXue on 13-1-19. // Copyri ...
- 【转】IOS 30多个iOS常用动画,带详细注释
原文: http://blog.csdn.net/zhibudefeng/article/details/8691567 CoreAnimationEffect.h 文件 // CoreAnimati ...
- iOS常用动画-b
CoreAnimationEffect.h // CoreAnimationEffect // // Created by VincentXue on 13-1-19. // Copyright ...
- 30多种iOS常用动画
转自:http://blog.csdn.net/zhibudefeng/article/details/8691567 // // CoreAnimationEffect.h // CoreAni ...
- iOS常用动画 类封装
//这是一个很好的动画封装类 很容易明白很详细 和大家分享 // CoreAnimationEffect.h // CoreAnimationEffect // // Created by Vince ...
- iOS 常用开源代码整理
本文章不定期整理. 1.AFNetworking AFNetworking 采用 NSURLConnection + NSOperation, 主要方便与服务端 API 进行数据交换, 操作简单, 功 ...
- iOS常用的代码块整理
strong @property (nonatomic,strong) <#Class#> *<#object#>; weak @property (nonatomic,wea ...
- IOS 常用功能代码
1. 关闭/隐藏键盘 resignFirstResponder 响应view的方法 -(IBAction)fname:(id)sender{ [sender resignFirstResponder] ...
随机推荐
- Java [Leetcode 88]CMerge Sorted Array
题目描述: Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array. N ...
- LeetCode:Sort List
Title: Sort a linked list in O(n log n) time using constant space complexity. 思路:考虑快速排序和归并排序,但是我的快速排 ...
- 利用ffmpeg解码h264流的代码
这里也直接给出代码: h264dec.h: #pragma once #include "tdll.h" #include "avcodec.h" #inclu ...
- 【ASP.NET】编程点滴 :ASP.NET身份验证
ASP.NET实际开发中身份验证 是一个不可回避的问题.在相当一段长的时间内,由于不求甚解,我对这个话题似懂非懂.今天就对它做个简单的小结. Authentication and Authorizat ...
- Android:真机调试,不显示logcat的解决方案
有时做开发的时候,用真机测试,总是看不到logcat信息 .原因是系统默认关闭了log,需要将其打开. 解决办法如下: 在拨号界面输入*#*#2846579#*#* ,然后系统会自动弹出一个菜单, ...
- SharePoint 2010 列表项事件接收器 ItemAdded 的使用方法
列表项事件处理器是继承于Microsoft.SharePoint.SPItemEventReceiver的类,Microsoft.SharePoint.SPItemEventReceiver类提供了许 ...
- 链表的倒数第K个节点
题目:输入一个链表,输出该链表中倒数第K个节点.为了符合大多数人的习惯,本题从1开始计数,即链表的尾节点是倒数第1个结点. package com.edu; class LinkNode{ //定义一 ...
- Easy steps to create a System Tray Application with C# z
Hiding the C# application to the system tray is quiet straight forward. With a few line of codes in ...
- 按钮点击WIN8 磁贴效果
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- HDU5731 Solid Dominoes Tilings 状压dp+状压容斥
题意:给定n,m的矩阵,就是求稳定的骨牌完美覆盖,也就是相邻的两行或者两列都至少有一个骨牌 分析:第一步: 如果是单单求骨牌完美覆盖,请先去学基础的插头dp(其实也是基础的状压dp)骨牌覆盖 hiho ...