旋转动画用控件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 > 0 ? _rotateDuration : defaultDuration)animations:^{self.transform = _defaultTransform;}];} else {self.transform = _defaultTransform;}}
- (void)changeToLeftAnimated:(BOOL)animated {if (animated) {[UIView animateWithDuration:(_rotateDuration > 0 ? _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 > 0 ? _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 > 0 ? _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 > 0 ? _fadeDuration : defaultDuration)animations:^{[self viewWithTag:UIVIEW_normalInputView].alpha = 1.f;}];} else {[self viewWithTag:UIVIEW_normalInputView].alpha = 1.f;}
}
- (void)fadeToDisableInputViewAnimated:(BOOL)animated {if (animated) {[UIView animateWithDuration:(_fadeDuration > 0 ? _fadeDuration : defaultDuration)animations:^{[self viewWithTag:UIVIEW_normalInputView].alpha = 0.f;}];} else {[self viewWithTag:UIVIEW_normalInputView].alpha = 0.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:nilafterDelay:7.f];// 延时
    [self performSelector:@selector(excuteEventTwo)withObject:nilafterDelay:9.f];
}
- (void)excuteEventOne {[_rotateView changeTodownAnimated:YES];[_rotateView fadeToDisableInputViewAnimated:YES];
}- (void)excuteEventTwo {[_rotateView changeToUpAnimated:YES];[_rotateView fadeToNormalInputViewAnimated:YES];
}@end

较为核心的地方:

 

转载于:https://www.cnblogs.com/YouXianMing/p/4152506.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/406695.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

UPS分类:直流UPS和交流UPS

以下资料来源于IT168术语详解&#xff1a;http://detail.it168.com/UPS从结构上一般分为直流UPS(DC-UPS)和交流UPS(AC-UPS)两大类。(1)直流UPS直流不间断电源由两个基本单元组成。分别是整流器、蓄电池。其原理结构方框图如下&#xff1a;其工作过程是&#xff1a;当市电正常时…

在python中可以使用urllib方便的实现图片和flash下载

非线程安全import urllib url “http://www.udooo.com/cooperate/qq/images/081128/left.swf” path “c:/spider/left.swf” data urllib.urlopen(url).read() f file(path,”wb”) f.write(data) f.close()线程安全python中还有更简洁的方法&#xff1a;import urllib ur…

HTTP1.0和HTTP1.1和HTTP2.0的区别

HTTP1.0和HTTP1.1和HTTP2.0的区别 1 HTTP1.0和HTTP1.1的区别 1.1 长连接(Persistent Connection) HTTP1.1支持长连接和请求的流水线处理&#xff0c;在一个TCP连接上可以传送多个HTTP请求和响应&#xff0c;减少了TCP的建立和关闭连接的消耗和延迟&#xff0c;在HTTP1.1中默…

PowerShell实战1:Ping_Test

功能&#xff1a;批量测试远程主机的Ping值&#xff0c;以及根据TTL值来判断是否为Windows主机。使用&#xff1a;在C:\IP.txt中加入需要测试的主机IP或域名&#xff0c;一行一个。例如&#xff1a; www.google.com www.baidu.com www.cha123.com www.yahoo.com www.msn.com源码…

5年后你最想要什么?

当你对自己的生命经常问为什么会这样的时候&#xff0c;你不妨试着问一下自己&#xff0c;你是否很清楚地知道自己要的是什么&#xff1f;如果连你自己要的是什么都不知道的话&#xff0c;那么爱你的亲人如何帮你安排呢&#xff1f;又岂能无端地怪亲人没有给你开路呢&#xff1…

TCP建立连接与断开连接的过程

在CS模式的TCP连接建立过程中&#xff0c;客户端与服务器端流程如下&#xff1a; 客户端流程&#xff1a;发送请求->接收服务器端确认->发送对服务器端确认的确认。 服务器端流程&#xff1a;接收客户端的连接建立请求->发送确认->接收客户端发送的对确认的确认。…

Session莫名丢失的原因及解决办法[转载]

Asp.net 默认配置下&#xff0c;Session莫名丢失的原因及解决办法 正常操作情况下Session会无故丢失。因为程序是在不停的被操作&#xff0c;排除Session超时的可能。另外&#xff0c;Session超时时间被设定成60分钟&#xff0c;不会这么快就超时的。 这次到CSDN上搜了一下帖子…

Python的构造函数和析构函数,对象和类的不一样

1.Python像其他的OOP语言一样在类里面会有构造和析构函数... 类似于PHP的, 构造和析构函数并不需要显式的写出来...他们只是在这个对象生成和销毁的时候才会被调用.. 如果显式的定义了,那么在对象被生成和销毁时就会分别的调用这两个函数 构造函数: __init__ 这个函数在用代码生…

Android控件捕获点击事件的范围

View的Tween动画过程中点击事件的位置并不会因为动画位置的改变而改变&#xff0c;是因为在动画过程中layout的位置实际上没有变&#xff0c;因此曾经一度认为View的点击事件&#xff08;其实不仅仅是点击事件&#xff0c;包括所有的触摸事件&#xff09;触发的范围是该View在l…

利用闭包实现onclick事件传递参数

当触发点击事件&#xff0c;一个简单的例子。 <!DOCTYPE html> <html> <head><title>闭包创建数组</title><meta charset"utf-8"><script type"text/javascript">window.onload function (){var lis documen…

ms sql 触发器( 转)

create trigger TgNameon tbfor updateas if update(recommend)begin update tb set commenddate(getdate()) from tb inner join inserted on tb.vlistidInserted.vlistidend关键在于Inserted表触发器语句中使用了两种特殊的表&#xff1a;deleted 表和 inserted 表。Dele…

Sicily 1034. Forest

题目地址&#xff1a;1034. Forest 思路&#xff1a; 网上很多说用深搜&#xff0c;很任性.......发现广搜也挺好用的&#xff0c;实验课打的(⊙o⊙)…orz........囧。 先找根结点&#xff0c;根据根结点广搜深度&#xff0c;广搜宽度&#xff0c;不过要开一个数组&#xff0c;…

Python中文全攻略

From: http://www.sqlite.com.cn/MySqlite/11/395.Html 1. 在Python中使用中文 在Python中有两种默认的字符串&#xff1a;str和unicode。在Python中一定要注意区分“Unicode字符串”和“unicode对象”的区别。后面所有的“unicode字符串”指的都是python里的“unicode…

HTTP 304状态码的详细讲解

HTTP 304状态码的详细讲解 304状态码或许不应该认为是一种错误&#xff0c;而是对客户端有缓存情况下服务端的一种响应。 整个请求响应过程如下&#xff1a; 客户端在请求一个文件的时候&#xff0c;发现自己缓存的文件有 Last Modified &#xff0c;那么在请求中会包含 If …

[MySQL FAQ]系列 -- 数据不算大,备份却非常慢

作/译者&#xff1a;叶金荣&#xff08;Email: &#xff09;&#xff0c;来源&#xff1a;http://imysql.cn&#xff0c;转载请注明作/译者和出处&#xff0c;并且不能用于商业用途&#xff0c;违者必究。问题环境硬件&#xff1a;DELL 1950, 146G SAS 15K RPMS * 2, 8G Ram软件…

视频编解码:第一章 编解码基础

1. 视频编码概念 视频编码方式就是指通过特定的压缩技术&#xff0c;将某个视频格式的文件转换成另一种视频格式文件的方式。 2. 为什么要进行视频压缩&#xff1f; 数据太大&#xff1a;未经压缩的数字视频数据量巨大存储困难&#xff1a;一张DVD只能存储几秒钟的未压缩数字视…

[python]删除列表中相同的元素

去除列表中重复的元素&#xff0c;非常简单&#xff0c;直接上代码&#xff1a; a [11, 21, 3, 4, 3, 2, 5] b list(set(a)) print(a) print(b)运行结果&#xff1a; E:\Program\Python>d.py [11, 21, 3, 4, 3, 2, 5] [2, 3, 4, 5, 11, 21]看到了吗&#xff0c;结果中确实…