旋转动画用控件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:nil
               afterDelay:7.f];
    
    // 延时
    [self performSelector:@selector(excuteEventTwo)
               withObject:nil
               afterDelay:9.f];
}
- (void)excuteEventOne {
    [_rotateView changeTodownAnimated:YES];
    [_rotateView fadeToDisableInputViewAnimated:YES];
}

- (void)excuteEventTwo {
    [_rotateView changeToUpAnimated:YES];
    [_rotateView fadeToNormalInputViewAnimated:YES];
}

@end

较为核心的地方:

 

目录
相关文章
|
Windows
Winform控件优化之背景透明那些事1:Button控件等背景透明
WinForm不支持真正的透明,其控件透明的实现都是背景颜色设置和对应位置的父控件背景相同。 Winform中控件的背景透明只有三种:Button控件的透明、其他控件的透明...
2930 0
Winform控件优化之背景透明那些事1:Button控件等背景透明
|
11月前
水波纹按钮动画
水波纹按钮动画
46 0
水波纹按钮动画
3d旋转动画焦点图
在线演示 本地下载
679 0
|
Android开发
Android 自定义控件之SlidingMenuVertical顶部悬浮(垂直折叠抽屉,有滑动渐变回调,可自行添加渐变动画)
顶部悬浮(垂直折叠抽屉,有滑动渐变回调,可自行添加渐变动画)
2071 0
|
C# 前端开发
WPF实现渐变淡入淡出的动画效果
原文:WPF实现渐变淡入淡出的动画效果 1、实现原理 1.1 利用UIElement.OpacityMask属性,用于改变对象区域的不透明度的画笔。可以使元素的特定区域透明或部分透明,从而实现比较新颖的效果。
3071 0
|
C#
WPF无边框拖动、全屏、缩放
原文:WPF无边框拖动、全屏、缩放 版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/lwwl12/article/details/78059361 先看效果 无边框 设置WindowStyle=”None”,窗口无关闭及缩放按钮,但还有黑边;设置AllowsTransparency=”True”,黑边没有了。
2110 0
|
C# 前端开发
WPF 一个弧形手势提示动画
原文:WPF 一个弧形手势提示动画 这是一个操作提示动画,一个小手在屏幕上按照一个弧形来回运动 ...
724 0
|
图形学
控件渐变色的实现
控件渐变色的实现(一)—— CAGradientLayer实现控件渐变色的实现(二)—— Core Graphics实现
785 0
|
C# 索引 容器
WPF ListView控件设置奇偶行背景色交替变换以及ListViewItem鼠标悬停动画
原文:WPF ListView控件设置奇偶行背景色交替变换以及ListViewItem鼠标悬停动画 利用WPF的ListView控件实现类似于Winform中DataGrid行背景色交替变换的效果,同时增加鼠标的悬停效果。
1837 0
关于圆角控件
如何新建shape文件:https://jingyan.baidu.com/article/b907e62795139746e7891cb9.html 如何在空间中加入shape.
755 0