旋转动画用控件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的更多相关文章

  1. 侧边栏下拉时箭头的旋转动画(treeView控件)

    //点击菜单时箭头旋转 let treeView = document.getElementsByClassName("treeview");//let解决闭包问题 let las ...

  2. 定制自己的动画 View 控件(Canvas 使用)

    定制自己的动画 View 控件(Canvas 使用) 如果要定义自己的 View 控件,则需要新建一个类继承 android.view.View.然后在 onDraw 中写自己需要实现的方式. 这里定 ...

  3. WPF 动画显示控件

    当我们要显示一个控件的时候,不仅仅要显示这个控件,还要有动画的效果. 主要用到了DoubleAnimation类. public static void ShowAnimation(object co ...

  4. android多框架实现短视频应用、3D手势旋转、banner控件、指南针、智能管家等应用源码

    Android精选源码 android智能管家app源码 Android高仿拼多多分类列表 Android百度地图实例详解之仿摩拜单车APP RecyclerView的LayoutManager搭建流 ...

  5. WPF设置动画在控件载入时就立刻执行

    <YourControl.Triggers> <EventTrigger RoutedEvent="YourControl.Loaded"><!--这 ...

  6. Android5.0新特性之——控件移动动画(初级)

    最近开发,UI大牛们设计了好多很炫酷吊炸天的动画,不由得重新学习了一下5.0的ObjectAnimator动画. ObjectAnimator动画的原理,通过反射控件的setXXX方法,改变控件的实际 ...

  7. 自己定义控件三部曲之动画篇(十三)——实现ListView Item进入动画

    前言:宝剑锋从磨砺出,梅花香自苦寒来 相关文章: <Android自己定义控件三部曲文章索引>: http://blog.csdn.net/harvic880925/article/det ...

  8. WPF ListView控件设置奇偶行背景色交替变换以及ListViewItem鼠标悬停动画

    原文:WPF ListView控件设置奇偶行背景色交替变换以及ListViewItem鼠标悬停动画 利用WPF的ListView控件实现类似于Winform中DataGrid行背景色交替变换的效果,同 ...

  9. iOS:风火轮活动刷新视图控件UIActivityIndicatorView的详细使用

    动态风火轮视图控件:UIActivityIndicatorView   介绍:它是一种类似于风火轮旋转的视图控件,可用作刷新数据时显示加载过程所用,继承自UIView.   类型: typedef N ...

随机推荐

  1. Java_无参数无返回类型方法及练习

    无参数无返回类型方法语法格式: public static void 方法名称(){ 方法体; } class Method03{ /*练习3:输出1-100中的每个数,要求使用无参无返回类型的方法完 ...

  2. redis虚拟内存---官方文档

    http://redis.io/topics/internals-vm Virtual Memory technical specification This document details the ...

  3. Beta阶段个人总结

    Beta阶段个人总结 这一次的项目在提出项目时有很大的信心能做好,但最后结果却不尽人意.由于这次的项目一开始目标是利用Android studio构建客户端然后电脑上连接数据库,在初期还未发现什么问题 ...

  4. pm2在node中的应用

    pm2 是一个带有负载均衡功能的Node应用的进程管理器,当你要把你的独立代码利用全部的服务器上的所有CPU,并保证进程永远都活着,0秒的重载, pm2是完美的. 主要特性: 内建负载均衡(使用Nod ...

  5. Asp.net MVC5系列——第一个项目

    转自http://www.cnblogs.com/wolf-sun/p/3888160.html 概述 在这一部分我们添加一个新的控制器HelloWorldController类,以便使用视图来向客户 ...

  6. 二、spring-boot-devtools热部署

    springboot提供了热部署,需要添加依赖: <dependency> <groupId> org.springframework.boot</groupId> ...

  7. fzu 2136 取糖果 好几种方法解决。

    Problem 2136 取糖果 Accept: 39    Submit: 101 Time Limit: 1000 mSec    Memory Limit : 32768 KB Problem ...

  8. Linux 安装 EPEL YUM源

    原文:https://blog.csdn.net/harbor1981/article/details/51135623 我们用yum安装软件时,经常发现我们的yum源里面没有该软件,需要自己去wge ...

  9. flask路由末端带斜线和不带斜线的区别

    路由末端带有“/” app.route('/test/') 在浏览器中输入http://127.0.0.1:5000/test/ 和http://127.0.0.1:5000/test都能访问 路由末 ...

  10. laravel5.7 表单验证

    laravel5.7 表单验证 一.创建表单请求 1.找到 larave5.7 文档 验证 中的创建表单请求,这里就要用到命令:php artisan make:request BrandReques ...