旋转动画用控件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;当市电正常时…

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源码…

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

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

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…

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 文件读和写

转载于:https://www.cnblogs.com/nzyjlr/p/4157582.html

element-ui 设置菜单栏展开

element-ui 侧边栏默认要全部展开怎么做&#xff1f; element-ui文档中是这么写的 default-openeds 当前打开的sub-menu的key数组 给标签加上这个属性 <el-menu class"el-menu-vertical" open"handleOpen" close"handleClose" theme"…

简单JS实现走马灯效果的文字(无需jQuery)

效果类似&#xff1a;(抱歉&#xff0c;图片是静态的) 写一段html&#xff0c;需要走马灯上下跳动的内容&#xff0c;但每次只显示一行&#xff1a;<hr size"0" align"center" style"border-top: 1px solid #F5F5F5;"/> <div id"m…

Android Service 生命周期

Android Service的生命周期 Managing the Lifecycle of a Service service的生命周期&#xff0c;从它被创建开始&#xff0c;到它被销毁为止&#xff0c;可以有两条不同的路径&#xff1a; A started service 被开启的service通过其他组件调用 startService()被创建。 这种ser…