//
// JumpToTransitionController.m
// CoreAnimationsDemo
//
// Created by Evan on 16/7/3.
// Copyright © 2016年 Evan. All rights reserved.
//
#define YSRandomColor [UIColor colorWithRed:arc4random_uniform(255)/255.0 green:arc4random_uniform(255)/255.0 blue:arc4random_uniform(255)/255.0 alpha:1]// 随机颜色
#import "JumpToTransitionController.h"
@interface JumpToTransitionController ()
@property (nonatomic, strong) UIView *viewRect;
@end
@implementation JumpToTransitionController
#pragma mark - LfileCycle
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"TransitionController首页";
UIButton *button = [UIButton createButton:@"改变导航栏标题" target:self action:@selector(changeNavBarTitle)];
button.frame = CGRectMake(80, 60, 200, 40);
[self.view addSubview:button];
self.viewRect = [[UIView alloc] initWithFrame:CGRectMake(80, 250, 100, 100)];
self.viewRect.backgroundColor = [UIColor yellowColor];
[self.view addSubview:_viewRect];
UIButton *changeSmallViewButton = [UIButton createButton:@"改变小view" target:self action:@selector(changeSmallView)];
changeSmallViewButton.frame = CGRectMake(80, 100, 200, 40);
[self.view addSubview:changeSmallViewButton];
UIButton *switchViewButton = [UIButton createButton:@"切换视图" target:self action:@selector(changeView)];
switchViewButton.frame = CGRectMake(80, 140, 200, 40);
[self.view addSubview:switchViewButton];
}
#pragma mark - Touch Event
- (void)changeNavBarTitle{
[self addAnimationAnimationduration:3.f type:kCATransitionReveal subtype:kCATransitionFromRight timingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut] control:self.navigationController.navigationBar];
}
- (void)changeSmallView {
[self addAnimationAnimationduration:3.f type:kCATransitionReveal subtype:kCATransitionFromRight timingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut] control:self.viewRect];
self.viewRect.backgroundColor = YSRandomColor;
}
- (void)changeView {
[self addAnimationAnimationduration:3.f type:kCATransitionReveal subtype:kCATransitionFromRight timingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut] control:self.view];
self.view.backgroundColor = YSRandomColor;
}
/**//
*animation: 创建动画类
* duration:动画的时间
* type:决定动画效果
* subtype:动画过渡方向
* timingFunction:动画样式
* control:为那个控件添加动画
*/
- (void)addAnimationAnimationduration:(NSInteger)duration type:(id)type subtype:(id)subtype timingFunction:(CAMediaTimingFunction *)timingFunction control:(UIView *)control {
CATransition *animation = [CATransition animation];
animation.duration = duration;
animation.type = type;
animation.subtype = subtype;
animation.timingFunction = timingFunction;
[control.layer addAnimation:animation forKey:nil];
}
网友评论