旋转动画用控件RotateView
生活随笔
收集整理的這篇文章主要介紹了
旋转动画用控件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
總結
以上是生活随笔為你收集整理的旋转动画用控件RotateView的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: UE4像素流送(Pixel Stream
- 下一篇: html中radio,checkbox值