IOS之基础动画
2016-05-12 09:40
381 查看
//
// ViewController.m
// 基础动画
//
// Created by 李江 on 16/5/12.
// Copyright © 2016年
李江. All rights reserved.
//
#import "ViewController.h"
@interface
ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super
viewDidLoad];
UIView *view1 = [[UIView
alloc]initWithFrame:self.view.frame];
view1.tag =
200;
view1.backgroundColor = [UIColor
redColor];
[self.view
addSubview:view1];
UIView *view2 = [[UIView
alloc]initWithFrame:self.view.frame];
view2.backgroundColor = [UIColor
grayColor];
view2.tag =
100;
[self.view
addSubview:view2];
}
//触摸屏幕时调用
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent
*)event{
[self
blockxchangeView];
}
//转场动画
-(void)exchangeView{
[UIView
beginAnimations:nil
context:nil];
[UIView
setAnimationCurve:UIViewAnimationCurveLinear];
[UIView
setAnimationDuration:1.5];
//设置转场效果
[UIView
setAnimationTransition:UIViewAnimationTransitionCurlUp
forView:self.view
cache:YES];
//实现转场
UIView *view1 = [self.view
viewWithTag:200];
UIView *view2 = [self.view
viewWithTag:100];
NSInteger indexOfview1 = [self.view.subviews
indexOfObject:view1];
NSInteger indexOfview2 = [self.view.subviews
indexOfObject:view2];
[self.view
exchangeSubviewAtIndex:indexOfview1
withSubviewAtIndex:indexOfview2];
[UIView
commitAnimations];
}
//block方式的转场动画
-(void)blockBaseAnimation{
UIView *view2 = [self.view
viewWithTag:100];
[UIView
animateWithDuration:2
animations:^{
view2.alpha =
0.2;
}completion:^(BOOL finished) {
[UIView
animateWithDuration:2
animations:^{
view2.alpha =
1;
}];
}];
}
//另一种block方式的专场动画
-(void)blockxchangeView{
[UIView
transitionWithView:self.view
duration:2
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
[self.view
exchangeSubviewAtIndex:2
withSubviewAtIndex:3];
} completion:^(BOOL finished) {
}];
}
//基础动画之缩小篇
-(void)baseAnimation{
//开始动画
[UIView
beginAnimations:@"view1"
context:@"缩小"];
//设置动画加速方式
[UIView
setAnimationCurve:UIViewAnimationCurveEaseInOut];
//动画时长
[UIView
setAnimationDuration:2.0];
//设置代理
[UIView
setAnimationDelegate:self];
//指定动画结束时执行的方法
[UIView
setAnimationDidStopSelector:@selector(animationDidStop:finished:)];
UIView *view2 = [self.view
viewWithTag:100];
CGRect rect = view2.frame;
rect.size =
CGSizeMake(100,
100);
view2.frame = rect;
view2.center =self.view.center;
}
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
}
- (void)didReceiveMemoryWarning {
[super
didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
// ViewController.m
// 基础动画
//
// Created by 李江 on 16/5/12.
// Copyright © 2016年
李江. All rights reserved.
//
#import "ViewController.h"
@interface
ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super
viewDidLoad];
UIView *view1 = [[UIView
alloc]initWithFrame:self.view.frame];
view1.tag =
200;
view1.backgroundColor = [UIColor
redColor];
[self.view
addSubview:view1];
UIView *view2 = [[UIView
alloc]initWithFrame:self.view.frame];
view2.backgroundColor = [UIColor
grayColor];
view2.tag =
100;
[self.view
addSubview:view2];
}
//触摸屏幕时调用
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent
*)event{
[self
blockxchangeView];
}
//转场动画
-(void)exchangeView{
[UIView
beginAnimations:nil
context:nil];
[UIView
setAnimationCurve:UIViewAnimationCurveLinear];
[UIView
setAnimationDuration:1.5];
//设置转场效果
[UIView
setAnimationTransition:UIViewAnimationTransitionCurlUp
forView:self.view
cache:YES];
//实现转场
UIView *view1 = [self.view
viewWithTag:200];
UIView *view2 = [self.view
viewWithTag:100];
NSInteger indexOfview1 = [self.view.subviews
indexOfObject:view1];
NSInteger indexOfview2 = [self.view.subviews
indexOfObject:view2];
[self.view
exchangeSubviewAtIndex:indexOfview1
withSubviewAtIndex:indexOfview2];
[UIView
commitAnimations];
}
//block方式的转场动画
-(void)blockBaseAnimation{
UIView *view2 = [self.view
viewWithTag:100];
[UIView
animateWithDuration:2
animations:^{
view2.alpha =
0.2;
}completion:^(BOOL finished) {
[UIView
animateWithDuration:2
animations:^{
view2.alpha =
1;
}];
}];
}
//另一种block方式的专场动画
-(void)blockxchangeView{
[UIView
transitionWithView:self.view
duration:2
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:^{
[self.view
exchangeSubviewAtIndex:2
withSubviewAtIndex:3];
} completion:^(BOOL finished) {
}];
}
//基础动画之缩小篇
-(void)baseAnimation{
//开始动画
[UIView
beginAnimations:@"view1"
context:@"缩小"];
//设置动画加速方式
[UIView
setAnimationCurve:UIViewAnimationCurveEaseInOut];
//动画时长
[UIView
setAnimationDuration:2.0];
//设置代理
[UIView
setAnimationDelegate:self];
//指定动画结束时执行的方法
[UIView
setAnimationDidStopSelector:@selector(animationDidStop:finished:)];
UIView *view2 = [self.view
viewWithTag:100];
CGRect rect = view2.frame;
rect.size =
CGSizeMake(100,
100);
view2.frame = rect;
view2.center =self.view.center;
}
-(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
}
- (void)didReceiveMemoryWarning {
[super
didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
相关文章推荐
- 【代码笔记】iOS-评分系统(小星星)
- 界面之间各种传值
- iOS9适配
- IOS中通知中心(NSNotificationCenter)的使用总结
- iOS对象间传值
- 《Motion Design for iOS》(十六)
- iOS应用程序中通过dispatch队列控制线程执行的方法
- [绍棠] iOS远程推送原理及实现过程
- iOS正则表达式运用
- iOS开发之AFNetworking 3.0.4使用
- iOS 集合的深复制与浅复制
- iOS开发——超链接富文本
- 关于友盟分享时“打开手机QQ失败”的一般解决方法
- IOS开发中的时间、日期问题
- 加速计原理 IOS4.0之前
- iOS中pch文件更简便的位置配置
- [10秒学会] - iOS tableView中headView和footView悬停方式
- iOS开发添加楷体字体(图解)
- iOS mvvm 框架设计
- iOS手势识别:识别原理和自定义手势识别