iOS Core Animation (本人写的源码)
来源:互联网 发布:我国对外投资数据 编辑:程序博客网 时间:2024/06/14 22:14
//
// ViewController.h
// Animation_byEpisode
//
// Created by Wangyun on 15/7/9.
// Copyright (c) 2015年 com.epsiode. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
// ViewController.m
// Animation_byEpisode
//
// Created by Wangyun on 15/7/9.
// Copyright (c) 2015年 com.epsiode. All rights reserved.
//
#import "ViewController.h"
#import "SecondViewController.h"
NSString * const string =@"123";
@interface ViewController ()
@property (strong,nonatomic) IBOutletUIImageView *imageView;
@property (strong,nonatomic) IBOutletUIImageView *colorImageView;
@property(nonatomic,retain)SecondViewController *secondVC;
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
self.imageView.image=[UIImageimageNamed:@"10042637.jpg"];
self.imageView.layer.cornerRadius=20;
self.imageView.layer.borderWidth=2;
self.imageView.layer.borderColor=[UIColorgreenColor].CGColor;
self.imageView.layer.shadowColor=[[UIColorblueColor] CGColor];
self.imageView.layer.shadowOffset=CGSizeMake(20,20);
self.imageView.layer.shadowOpacity=0.5;
[self.imageViewsetClipsToBounds:YES];
//超过主层边框范围的内容都裁剪
self.imageView.layer.masksToBounds=NO;
//[self testImageView];
self.colorImageView.backgroundColor=[UIColorpurpleColor];
self.colorImageView.layer.cornerRadius=20;
self.colorImageView.layer.borderWidth=2;
self.colorImageView.layer.borderColor=[UIColorgreenColor].CGColor;
self.colorImageView.layer.shadowColor=[[UIColoryellowColor]CGColor];
self.colorImageView.layer.shadowOffset=CGSizeMake(20,20);
self.colorImageView.layer.shadowOpacity=0.5;
[self.colorImageViewsetClipsToBounds:YES];
self.colorImageView.layer.masksToBounds=NO;
self.secondVC=[self.storyboardinstantiateViewControllerWithIdentifier:@"secondVC"];
}
-(void)testImageView{
//[self.imageView.layer setValue:@(M_PI_4) forKeyPath:@"transform.rotation"];
// NSValue *value=[NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_4, 0, 0, 1)];
// [self.imageView.layer setValue:value forKeyPath:@"transform"];
//[self.imageView.layer setValue:[NSValue valueWithCATransform3D:CATransform3DMakeRotation(M_PI_4, 0, 0, 1)] forKeyPath:@"transform"];
// [self.imageView.layer setValue:[NSNumber numberWithFloat:0.5] forKeyPath:@"transform.scale.y"];
[self.imageView.layersetValue:@(0.5)forKeyPath:@"transform.scale.y"];
}
//UIView动画的动画块方法
- (IBAction)propertyAnimation:(UIButton *)sender {
[UIViewbeginAnimations:@"AnimationOne"context:nil];
[UIViewsetAnimationDuration:1];
[UIViewsetAnimationRepeatCount:2];
//[UIView setAnimationDelegate:self]; 这个有什么用??
self.colorImageView.bounds=CGRectMake(120,80, 100, 100);
self.colorImageView.layer.cornerRadius=50;
self.colorImageView.transform=CGAffineTransformMakeRotation(M_PI);
[UIViewcommitAnimations];
}
//UIView动画的block方法
- (IBAction)blockAnimation:(UIButton *)sender {
[UIViewanimateWithDuration:1delay:1options:UIViewAnimationOptionTransitionFlipFromBottomanimations:^{
self.colorImageView.bounds=CGRectMake(0,0, 200, 200);
self.colorImageView.transform=CGAffineTransformMakeRotation(2*M_PI);
} completion:^(BOOL finished) {
}];
}
- (IBAction)transmitAnimation:(UIButton *)sender {
UIView *view=self.view.superview;
[UIViewbeginAnimations:@"transmit"context:nil];
[UIViewsetAnimationDuration:3];
[UIViewsetAnimationTransition:UIViewAnimationTransitionCurlUpforView:self.view.superviewcache:YES];
[self.viewremoveFromSuperview];
[view addSubview:self.secondVC.view];
[UIViewcommitAnimations];
}
//UIViewTransition的API方法
- (IBAction)blockTransmitAnimation:(UIButton *)sender {
[UIViewtransitionFromView:self.viewtoView:self.secondVC.viewduration:1options:UIViewAnimationOptionTransitionCurlUpcompletion:^(BOOL finished) {
}];
UIView *view=self.view.superview;
[UIViewtransitionWithView:view duration:1options:UIViewAnimationOptionTransitionCurlUpanimations:^{
[self.viewremoveFromSuperview];
[view addSubview:self.secondVC.view];
} completion:^(BOOL finished) {
}];
}
//CAAnimation是抽象类,CAPropertyAnimation-->CABasicAnimation
- (IBAction)basicAnimation:(UIButton *)sender {
CABasicAnimation *basicAnimation=[CABasicAnimationanimationWithKeyPath:@"backgroundColor"];
basicAnimation.duration=6;
basicAnimation.fromValue = (__bridgeid)([[UIColorredColor] CGColor]);
basicAnimation.toValue = (__bridgeid)([[UIColorpurpleColor] CGColor]);
// basicAnimation.fromValue = [NSNumber numberWithFloat:0.5];
// basicAnimation.byValue = [NSNumber numberWithFloat:0.2];
[self.colorImageView.layeraddAnimation:basicAnimation forKey:@"haha"];
self.colorImageView.backgroundColor=[UIColoryellowColor];
}
//CAAnimation是抽象类,CAPropertyAnimation-->CAKeyFrameAnimation
- (IBAction)keyFrameAnimation:(UIButton *)sender {
CAKeyframeAnimation *keyFrameAnimation=[CAKeyframeAnimationanimationWithKeyPath:@"position.x"];
CGFloat center=self.colorImageView.layer.position.x;
CGFloat left=center-20;
CGFloat right=center+20;
NSNumber *c=[NSNumbernumberWithFloat:center];
NSNumber *l=[NSNumbernumberWithFloat:left];
NSNumber *r=[NSNumbernumberWithFloat:right];
keyFrameAnimation.values=@[c,r,l,c,l,r,c,r,l,r,c,l];
[self.colorImageView.layeraddAnimation:keyFrameAnimation forKey:@"shake"];
}
//CATransition,作⽤:layer的过渡动画
//有两个主要属性:type(设置过渡动画的效果)和subType(设置过渡动画的⽅方向)
- (IBAction)coreAnimation:(UIButton *)sender {
CATransition *transition=[CATransitionanimation];
transition.duration=3;
transition.startProgress=0.5;
transition.type=@"cube";
transition.subtype=kCATransitionFromLeft;
UIView *view =self.view.superview;
[view.layer addAnimation:transitionforKey:@"过渡"];
[self.viewremoveFromSuperview];
[view addSubview:self.secondVC.view];
}
//CAAnimation是抽象类,CAAnimationGroup-->CAAnimationGroup只有⼀一个数组属性,可以添加多个 CAAnimation,⼀一起执⾏行
- (IBAction)groupAnimation:(UIButton *)sender {
CAAnimationGroup *groupAnimation=[CAAnimationGroupanimation];
CABasicAnimation *basicAnimation=[CABasicAnimationanimationWithKeyPath:@"position"];
basicAnimation.fromValue=[NSValuevalueWithCGPoint:self.colorImageView.layer.position];
basicAnimation.toValue=[NSValuevalueWithCGPoint:CGPointMake(50,300)];
CABasicAnimation *basicAnimation1=[CABasicAnimationanimationWithKeyPath:@"color"];
basicAnimation1.fromValue = (__bridgeid)([[UIColorredColor] CGColor]);
basicAnimation1.toValue = (__bridgeid)([[UIColorpurpleColor] CGColor]);
groupAnimation.duration=3;
groupAnimation.animations=@[basicAnimation,basicAnimation1];
[self.colorImageView.layeraddAnimation:groupAnimation forKey:@"2"];
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
// FirstViewController.h
// Animation_byEpisode
//
// Created by Wangyun on 15/7/9.
// Copyright (c) 2015年 com.epsiode. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface FirstViewController : UIViewController
@end
// FirstViewController.m
// Animation_byEpisode
//
// Created by Wangyun on 15/7/9.
// Copyright (c) 2015年 com.epsiode. All rights reserved.
//
#import "FirstViewController.h"
#import "Macro.h"
#import "ViewController.h"
@interface FirstViewController ()
@end
@implementation FirstViewController
- (void)viewDidLoad {
[superviewDidLoad];
[selfbootAnimation];
}
-(void)bootAnimation{
UIImageView *bootImageView=[[UIImageViewalloc] initWithFrame:[UIScreenmainScreen].bounds];
bootImageView.image=[UIImageimageNamed:@"zhiyan"];
[self.viewaddSubview:bootImageView];
[UIViewanimateWithDuration:3delay:0options:UIViewAnimationOptionOverrideInheritedDurationanimations:^{
bootImageView.frame=CGRectMake(-30, -50,kScreen_Width+60,kScreen_Height+100);
} completion:^(BOOL finished) {
[bootImageView removeFromSuperview];
ViewController *viewC=[self.storyboardinstantiateViewControllerWithIdentifier:@"viewVC"];
//[self.view removeFromSuperview];
[self.viewaddSubview:viewC.view];
}];
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
//
// SecondViewController.h
// Animation_byEpisode
//
// Created by Wangyun on 15/7/9.
// Copyright (c) 2015年 com.epsiode. All rights reserved.
//
#import <UIKit/UIKit.h>
extern NSString *const string;
@interface SecondViewController : UIViewController
@end
// SecondViewController.m
// Animation_byEpisode
//
// Created by Wangyun on 15/7/9.
// Copyright (c) 2015年 com.epsiode. All rights reserved.
//
#import "SecondViewController.h"
#import "ViewController.h"
@interface SecondViewController ()
@property(nonatomic,retain)ViewController *viewController;
@end
@implementation SecondViewController
- (void)viewDidLoad {
[superviewDidLoad];
NSLog(@"string :%@",string);
_viewController=[self.storyboardinstantiateViewControllerWithIdentifier:@"viewVC"];
}
- (IBAction)swiftBack:(UIButton *)sender {
[UIViewtransitionFromView:self.viewtoView:self.viewController.viewduration:1options:UIViewAnimationOptionTransitionCurlDowncompletion:^(BOOL finished) {
}];
UIView *view=self.view.superview;
[UIViewtransitionWithView:view duration:1options:UIViewAnimationOptionTransitionCurlDownanimations:^{
[self.viewremoveFromSuperview];
[view addSubview:self.viewController.view];
} completion:^(BOOL finished) {
}];
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
- iOS Core Animation (本人写的源码)
- iphone ios CORE ANIMATION的学习备忘录(第一天)
- iOS开发有关Core Animation的介绍
- iOS:Core Animation笔记(1)
- iOS-Core-Animation-Advanced-Techniques(一)
- iOS-Core-Animation-Advanced-Techniques(二)
- iOS-Core-Animation-Advanced-Techniques(四)
- iOS-Core-Animation-Advanced-Techniques(一)
- iOS-Core-Animation-Advanced-Techniques(二)
- iOS-Core-Animation-Advanced-Techniques(四)
- iOS-Core-Animation-Advanced-Techniques(一)
- iOS-Core-Animation-Advanced-Techniques(二)
- iOS-Core-Animation-Advanced-Techniques(四)
- iOS-Core-Animation-Advanced-Techniques(一)
- iOS-Core-Animation-Advanced-Techniques(二)
- iOS-Core-Animation-Advanced-Techniques(四)
- iOS-Core-Animation-Advanced-Techniques(一)
- iOS-Core-Animation-Advanced-Techniques(二)
- 关于HIPAA
- Loadrunner模拟JSON接口请求进行测试
- iOS UIView视图抖动效果
- 关于字符串的处理
- MySQL数据库:case when then else end
- iOS Core Animation (本人写的源码)
- 键盘遮挡解决
- Web测试用例总结
- Android根据经纬度获取地址,眼前一亮
- aws EC2 挂载 其它卷(aws EC2 网络配置出错,不能 ssh 连接时,需要启动一个新实例,去挂载 这个出错的卷,来修改卷里的错误配置)
- python实现的控制台进度条
- 《Android源码设计模式解析与实战》读书笔记(十二)
- iOS -- 获取当前时间,以及出现的错误
- Spring - 注解的使用 和 继承的配置