旋转动画用控件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 ...
随机推荐
- uvm_cmdline_processor
无意中看到uvm_cmdline_processor,之前使用+UVM_TESTNAME也没深究,现在记录一下 内部调用脚本中的参数,通过使用uvm_cmdline_processor可以从脚本层级, ...
- unity代码设置鼠标样式
public class Main : MonoBehaviour { public Texture2D cursorTexture;//图片 public CursorMode cursorMode ...
- 【c++】常识易混提示
1. struct 和 class 唯一的区别:默认的成员保护级别和默认的派生保护级别不同(前者为public,后者为private). 2. int *p = new int[23]; de ...
- Java代码在本地运行没有问题。上传到阿里云服务器后。出现了中文乱码解决
java -Dfile.encoding=UTF-8 -jar project.jar
- NOI 2018 酱油记
转眼离 NOI 2018 已经过了一个星期了,退役的我还是随便来水水吧. 语法.错字之类的可能会很多,但是我也不拘这点小节了. 恭喜 yww, zjt, sk 进队,zwl, myh au , yay ...
- Magento 2开发教程 - 如何添加新产品属性
添加产品属性是一种在Magento 1 和 Magento 2最受欢迎的业务. 属性是解决许多与产品相关的实际任务的有力方法. 这是一个相当广泛的话题,但在这个视频中,我们将讨论添加一个下拉类型属性到 ...
- git提交空文件夹和删除远程文件
git提交空文件夹 在文件夹中创建 .gitkeep 文件,文件内容如下 # Ignore everything in this directory * # Except this file !.gi ...
- 宏定义中的反斜杠"\"和宏定义的细节说明
转载自:http://www.wtoutiao.com/p/K6csca.html 在阅读C语言代码经常可以看到代码中出现反斜杠"\",不是很明白它的意思,遂对反斜杠"\ ...
- Java 基础(4)——常量 & 注释
hello 呀,今天的内容超简单( ̄︶ ̄)↗并且,还有暗藏福利哟~~ 常量 常量 就是常常不变的量,第一次定义之后,就不会发生改变了.可能这就是 “常量” 的来源吧哈哈哈(玩笑). 一般来说,常量的定 ...
- 一、python简单爬取静态网页
一.简单爬虫框架 简单爬虫框架由四个部分组成:URL管理器.网页下载器.网页解析器.调度器,还有应用这一部分,应用主要是NLP配合相关业务. 它的基本逻辑是这样的:给定一个要访问的URL,获取这个ht ...