旋转动画用控件RotateView
旋转动画用控件RotateView

最终效果:

源码:
RotateView.h 与 RotateView.m
//
// RotateView.h
// RotateAnimationView
//
// Created by YouXianMing on 14/12/8.
// Copyright (c) 2014年 YouXianMing. All rights reserved.
// #import <UIKit/UIKit.h> /**
* 要注意normalInputView与disableInputView的frame值最好与RotateView的bounds值一致
*/
@interface RotateView : UIView /**
* 显示常规的view
*/
@property (nonatomic, strong) UIView *normalInputView;
/**
* 禁用状态的view
*/
@property (nonatomic, strong) UIView *disableInputView;
/**
* 旋转时间
*/
@property (nonatomic, assign) CGFloat rotateDuration;
/**
* view切换时间
*/
@property (nonatomic, assign) CGFloat fadeDuration; /**
* 旋转到向上的位置(默认的位置)
*
* @param animated 是否显示动画
*/
- (void)changeToUpAnimated:(BOOL)animated; /**
* 旋转到向左的位置
*
* @param animated 是否显示动画
*/
- (void)changeToLeftAnimated:(BOOL)animated; /**
* 旋转到向右的位置
*
* @param animated 是否显示动画
*/
- (void)changeToRightAnimated:(BOOL)animated; /**
* 旋转到向下的位置
*
* @param animated 是否显示动画
*/
- (void)changeTodownAnimated:(BOOL)animated; /**
* 渐变到显示常规的view
*
* @param animated 是否显示动画
*/
- (void)fadeToNormalInputViewAnimated:(BOOL)animated; /**
* 渐变到禁用状态的view
*
* @param animated 是否显示动画
*/
- (void)fadeToDisableInputViewAnimated:(BOOL)animated; @end
//
// RotateView.m
// RotateAnimationView
//
// Created by YouXianMing on 14/12/8.
// Copyright (c) 2014年 YouXianMing. All rights reserved.
// #import "RotateView.h" static CGFloat defaultDuration = 0.25f; typedef enum : NSUInteger {
UIVIEW_normalInputView = 0xEEFF,
UIVIEW_disableInputView,
} EnumRotateView; @interface RotateView ()
@property (nonatomic, assign) CGAffineTransform defaultTransform;
@end @implementation RotateView - (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_defaultTransform = self.transform;
}
return self;
} #pragma mark - 动画的执行
- (void)changeToUpAnimated:(BOOL)animated {
if (animated) {
[UIView animateWithDuration:(_rotateDuration > ? _rotateDuration : defaultDuration)
animations:^{
self.transform = _defaultTransform;
}];
} else {
self.transform = _defaultTransform;
} }
- (void)changeToLeftAnimated:(BOOL)animated {
if (animated) {
[UIView animateWithDuration:(_rotateDuration > ? _rotateDuration : defaultDuration)
animations:^{
self.transform = CGAffineTransformRotate(_defaultTransform, -M_PI_2);
}];
} else {
self.transform = CGAffineTransformRotate(_defaultTransform, -M_PI_2);
}
}
- (void)changeToRightAnimated:(BOOL)animated {
if (animated) {
[UIView animateWithDuration:(_rotateDuration > ? _rotateDuration : defaultDuration)
animations:^{
self.transform = CGAffineTransformRotate(_defaultTransform, M_PI_2);
}];
} else {
self.transform = CGAffineTransformRotate(_defaultTransform, M_PI_2);
}
}
- (void)changeTodownAnimated:(BOOL)animated {
if (animated) {
[UIView animateWithDuration:(_rotateDuration > ? _rotateDuration : defaultDuration)
animations:^{
self.transform = CGAffineTransformRotate(_defaultTransform, M_PI);
}];
} else {
self.transform = CGAffineTransformRotate(_defaultTransform, M_PI);
}
}
- (void)fadeToNormalInputViewAnimated:(BOOL)animated {
if (animated) {
[UIView animateWithDuration:(_fadeDuration > ? _fadeDuration : defaultDuration)
animations:^{
[self viewWithTag:UIVIEW_normalInputView].alpha = .f;
}];
} else {
[self viewWithTag:UIVIEW_normalInputView].alpha = .f;
}
}
- (void)fadeToDisableInputViewAnimated:(BOOL)animated {
if (animated) {
[UIView animateWithDuration:(_fadeDuration > ? _fadeDuration : defaultDuration)
animations:^{
[self viewWithTag:UIVIEW_normalInputView].alpha = .f;
}];
} else {
[self viewWithTag:UIVIEW_normalInputView].alpha = .f;
}
} #pragma mark - 重写setter,getter方法
@synthesize normalInputView = _normalInputView;
- (void)setNormalInputView:(UIView *)normalInputView {
normalInputView.frame = normalInputView.bounds;
normalInputView.userInteractionEnabled = NO;
normalInputView.tag = UIVIEW_normalInputView;
[self addSubview:normalInputView]; [self bringSubviewToFront:normalInputView];
}
- (UIView *)normalInputView {
return [self viewWithTag:UIVIEW_normalInputView];
} @synthesize disableInputView = _disableInputView;
- (void)setDisableInputView:(UIView *)disableInputView {
disableInputView.frame = disableInputView.bounds;
disableInputView.userInteractionEnabled = NO;
disableInputView.tag = UIVIEW_disableInputView;
[self addSubview:disableInputView]; [self sendSubviewToBack:disableInputView];
}
- (UIView *)disableInputView {
return [self viewWithTag:UIVIEW_disableInputView];
} @end
使用的源码:
//
// ViewController.m
// CircleView
//
// Created by YouXianMing on 14/12/9.
// Copyright (c) 2014年 YouXianMing. All rights reserved.
// #import "ViewController.h"
#import "RotateView.h" @interface ViewController () @property (nonatomic, strong) RotateView *rotateView; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; // 输入图片与输出图片
UIImageView *normalView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"normal"]];
UIImageView *disableView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"disable"]]; // 旋转的view
_rotateView = [[RotateView alloc] initWithFrame:normalView.bounds];
_rotateView.center = self.view.center;
_rotateView.normalInputView = normalView;
_rotateView.disableInputView = disableView;
[self.view addSubview:_rotateView]; // 延时
[self performSelector:@selector(excuteEventOne)
withObject:nil
afterDelay:.f]; // 延时
[self performSelector:@selector(excuteEventTwo)
withObject:nil
afterDelay:.f];
}
- (void)excuteEventOne {
[_rotateView changeTodownAnimated:YES];
[_rotateView fadeToDisableInputViewAnimated:YES];
} - (void)excuteEventTwo {
[_rotateView changeToUpAnimated:YES];
[_rotateView fadeToNormalInputViewAnimated:YES];
} @end
较为核心的地方:

旋转动画用控件RotateView的更多相关文章
- 侧边栏下拉时箭头的旋转动画(treeView控件)
//点击菜单时箭头旋转 let treeView = document.getElementsByClassName("treeview");//let解决闭包问题 let las ...
- 定制自己的动画 View 控件(Canvas 使用)
定制自己的动画 View 控件(Canvas 使用) 如果要定义自己的 View 控件,则需要新建一个类继承 android.view.View.然后在 onDraw 中写自己需要实现的方式. 这里定 ...
- WPF 动画显示控件
当我们要显示一个控件的时候,不仅仅要显示这个控件,还要有动画的效果. 主要用到了DoubleAnimation类. public static void ShowAnimation(object co ...
- android多框架实现短视频应用、3D手势旋转、banner控件、指南针、智能管家等应用源码
Android精选源码 android智能管家app源码 Android高仿拼多多分类列表 Android百度地图实例详解之仿摩拜单车APP RecyclerView的LayoutManager搭建流 ...
- WPF设置动画在控件载入时就立刻执行
<YourControl.Triggers> <EventTrigger RoutedEvent="YourControl.Loaded"><!--这 ...
- Android5.0新特性之——控件移动动画(初级)
最近开发,UI大牛们设计了好多很炫酷吊炸天的动画,不由得重新学习了一下5.0的ObjectAnimator动画. ObjectAnimator动画的原理,通过反射控件的setXXX方法,改变控件的实际 ...
- 自己定义控件三部曲之动画篇(十三)——实现ListView Item进入动画
前言:宝剑锋从磨砺出,梅花香自苦寒来 相关文章: <Android自己定义控件三部曲文章索引>: http://blog.csdn.net/harvic880925/article/det ...
- WPF ListView控件设置奇偶行背景色交替变换以及ListViewItem鼠标悬停动画
原文:WPF ListView控件设置奇偶行背景色交替变换以及ListViewItem鼠标悬停动画 利用WPF的ListView控件实现类似于Winform中DataGrid行背景色交替变换的效果,同 ...
- iOS:风火轮活动刷新视图控件UIActivityIndicatorView的详细使用
动态风火轮视图控件:UIActivityIndicatorView 介绍:它是一种类似于风火轮旋转的视图控件,可用作刷新数据时显示加载过程所用,继承自UIView. 类型: typedef N ...
随机推荐
- oracle 表空间tablespace
一.Oracle 表空间的组成 Everoone knows Oracle数据库真正存放数据的是数据文件,Oracle表空间是逻辑上的概念,他在物理上是并不存在的,把多个DataFile合并到一起就是 ...
- Git学习系列之Git 的缺点有哪些?
不多说,直接上干货 前面,谈及了 Git学习系列之Git 的优势有哪些? 缺点: (1)资料少(起码中文资料很少). (2)学习周期相对而言比较长. (3)不符合常规思维. (4)代码保密性差,一旦开 ...
- Git学习系列之Git产生的背景
不多说,直接上干货! 史上最浅显易懂的Git教程! 为什么要编写这个教程?因为我在学习Git的过程中,买过书,也在网上Google了一堆Git相关的文章和教程,但令人失望的是,这些教程不是难得令人发指 ...
- ServletRequestLister
1 知识点
- <数据挖掘导论>读书笔记2
1.频率和众数 frequency(vi)=具有属性值vi的对象数/m 分类属性的众数mode是具有最高频率的值. 2.百分位数 3.位置度量:均值和中位数 4.散布度量:极差和方差 绝对平均偏差 A ...
- 前端渲染模板(一):Thymeleaf
一.使用 本篇文章将以SpringBoot为框架来介绍Thymeleaf的用法. 1 资源文件的约定目录结构 Maven的资源文件目录:/src/java/resources spring-boot ...
- Lucene学习之四:Lucene的索引文件格式(3)
本文转载自:http://www.cnblogs.com/forfuture1978/archive/2010/02/02/1661436.html ,略有删改和备注. 四.具体格式 4.2. 反向信 ...
- [android] 网络链接类型和渠道
1.实现方式 1.1使用HttpUrlConnection 1.2使用HttpClient 1.3使用Socket,比如:豌豆荚,聊天工具 2.通讯渠道 2.1 WLAN(wi-fi),100米左右的 ...
- xcode8 打开的 xib 踩坑
之前开发都不敢工测试版的开发,一直用正式版的,xcode7.3.1的模糊匹配让我很蛋疼,自定义的类,类名不提示,每次都粘贴复制,8号苹果发布了 xcode8GM 版,迫不及待的从苹果开发者官网下了一个 ...
- Docker安装和状态查询指令
1 .安装 Docker $ yum install -y docker-engine 2.启动docker $systemctl start docker.service 3.验证安装是否成功(有c ...