您的位置:首页 > 移动开发 > IOS开发

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: