旋转动画用控件RotateView
2024-08-27 20:09:29
旋转动画用控件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
较为核心的地方:
最新文章
- 淡蓝风格的手机登录HTML模板
- C++的最佳特性(译)
- 锋利的jQuery-3--用js给多选的checkbox或者select赋值
- 4.2 EF的CRUD控制器代码
- ENVI二次开发模式下的Landsat数据读取
- MySQL数据库最大连接数
- 剑指Offer23 二叉树中和为sum的路径
- PHP运行模式的深入理解
- springmvc 传递对象数组参数 property path is neither an array nor a List nor a Map
- jQuery对象和Dom对象的区分以及之间转换
- 10. 管理Apache ZooKeeper配置
- ranker_worker.go
- 筛选最小值---verilog
- Hadoop记录-hadoop和hbase监控有那些比较好的工具
- WWDC 17: 开发者的最初观感
- Javascript中的闭包 O__O ";…
- PHP + NGINX 控制视频文件播放,并防止文件下载
- spring boot实现异步调用
- opencv附加依赖性选择,提示找不到opencv_world400d.dll
- VB ASP 使用 now() 时默认格式调整方法