动画:UIKitAnimation 简单动画学习 iOS (一) 渐变 、 移动 、翻页、来回翻转
2012-08-10 15:02
363 查看
转载请说明(谢谢) http://blog.csdn.net/a21064346/article/details/7851695
点击打开链接
以下 一个系列的 动画效果 在 UIView.h文件中可以查找。但是比较炫丽的一些动画,就需要用到下一章节的coreAnimation。其中需要添加
QuartzCore
CoreGraphics
这两个framework
本人偷懒,就不搭建框架了。自己把方法复制到m文件里:)
//渐变 和 移动
- (UIGestureRecognizer *)createTapRecognizerWithSelector:(SEL)selector {
return [[[UITapGestureRecognizeralloc]initWithTarget:selfaction:selector]autorelease];
}
- (void)viewDidLoad {
[superviewDidLoad];
fadeMeView = [[UIViewalloc]initWithFrame:CGRectMake(55,40,210,160)];
fadeMeView.backgroundColor
= [UIColorcolorWithRed:0.580green:0.706blue:0.796alpha:1.000];
[self.viewaddSubview:fadeMeView];
moveMeView = [[UIViewalloc]initWithFrame:CGRectMake(55,220,210,160)];
moveMeView.backgroundColor
= [UIColorcolorWithRed:1.000green:0.400blue:0.400alpha:1.000];
[self.viewaddSubview:moveMeView];
[fadeMeViewaddGestureRecognizer:[selfcreateTapRecognizerWithSelector:@selector(fadeMe)]];
[moveMeViewaddGestureRecognizer:[selfcreateTapRecognizerWithSelector:@selector(moveMe)]];
}
- (void)fadeMe {
[UIViewanimateWithDuration:1.0animations:^{
fadeMeView.alpha
= 0.0f;
}];
}
- (void)moveMe {
[UIViewanimateWithDuration:0.5animations:^{
moveMeView.center
= CGPointMake(moveMeView.center.x,moveMeView.center.y
-200);
}];
}
//翻书 翻页效果
- (void)CurlUp {
[UIViewtransitionWithView:noteViewduration:0.6
options:UIViewAnimationOptionTransitionCurlUp
animations:^{
NSString *currentText =noteView.text;
noteView.text =nextText;
self.nextText = currentText;
}completion:^(BOOL finished){
}];
}
//同一容器中, view 左右来回翻转替换
- (void)viewDidLoad {
[superviewDidLoad];
self.title = [[selfclass]displayName];
// Set the background color for the window. The user will see the window's background color on the transition.
UIColor *backgroundColor = [UIColorcolorWithPatternImage:[UIImageimageNamed:@"pattern.png"]];
[UIApplicationsharedApplication].keyWindow.backgroundColor
= backgroundColor;
frontView = [[UIViewalloc]initWithFrame:self.view.bounds];
frontView.backgroundColor
= [UIColorcolorWithRed:0.345green:0.349blue:0.365alpha:1.000];
UIImageView *caLogoView = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"caLogo.png"]];
caLogoView.frame =CGRectMake(70,80,
caLogoView.bounds.size.width, caLogoView.bounds.size.height);
[frontViewaddSubview:caLogoView];
UIImage *backImage = [UIImageimageNamed:@"backView.png"];
backView = [[UIImageViewalloc]initWithImage:backImage];
backView.userInteractionEnabled
= YES;
[self.viewaddSubview:backView];
[self.viewaddSubview:frontView];
displayingFrontView =YES;
UIGestureRecognizer *frontViewTapRecognizer = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(flipViews)];
UIGestureRecognizer *backViewTapRecognizer = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(flipViews)];
[frontViewaddGestureRecognizer:frontViewTapRecognizer];
[backViewaddGestureRecognizer:backViewTapRecognizer];
[frontViewTapRecognizerrelease];
[backViewTapRecognizerrelease];
}
- (void)flipViews {
[UIViewtransitionFromView:(displayingFrontView)
?frontView : backView
toView:(displayingFrontView)
? backView : frontView
duration:0.75
options:(displayingFrontView
?UIViewAnimationOptionTransitionFlipFromRight :UIViewAnimationOptionTransitionFlipFromLeft)
completion:^(BOOL finished) {
if (finished) {
displayingFrontView = !displayingFrontView;
}
}];
}
点击打开链接
以下 一个系列的 动画效果 在 UIView.h文件中可以查找。但是比较炫丽的一些动画,就需要用到下一章节的coreAnimation。其中需要添加
QuartzCore
CoreGraphics
这两个framework
本人偷懒,就不搭建框架了。自己把方法复制到m文件里:)
//渐变 和 移动
- (UIGestureRecognizer *)createTapRecognizerWithSelector:(SEL)selector {
return [[[UITapGestureRecognizeralloc]initWithTarget:selfaction:selector]autorelease];
}
- (void)viewDidLoad {
[superviewDidLoad];
fadeMeView = [[UIViewalloc]initWithFrame:CGRectMake(55,40,210,160)];
fadeMeView.backgroundColor
= [UIColorcolorWithRed:0.580green:0.706blue:0.796alpha:1.000];
[self.viewaddSubview:fadeMeView];
moveMeView = [[UIViewalloc]initWithFrame:CGRectMake(55,220,210,160)];
moveMeView.backgroundColor
= [UIColorcolorWithRed:1.000green:0.400blue:0.400alpha:1.000];
[self.viewaddSubview:moveMeView];
[fadeMeViewaddGestureRecognizer:[selfcreateTapRecognizerWithSelector:@selector(fadeMe)]];
[moveMeViewaddGestureRecognizer:[selfcreateTapRecognizerWithSelector:@selector(moveMe)]];
}
- (void)fadeMe {
[UIViewanimateWithDuration:1.0animations:^{
fadeMeView.alpha
= 0.0f;
}];
}
- (void)moveMe {
[UIViewanimateWithDuration:0.5animations:^{
moveMeView.center
= CGPointMake(moveMeView.center.x,moveMeView.center.y
-200);
}];
}
//翻书 翻页效果
- (void)CurlUp {
[UIViewtransitionWithView:noteViewduration:0.6
options:UIViewAnimationOptionTransitionCurlUp
animations:^{
NSString *currentText =noteView.text;
noteView.text =nextText;
self.nextText = currentText;
}completion:^(BOOL finished){
}];
}
//同一容器中, view 左右来回翻转替换
- (void)viewDidLoad {
[superviewDidLoad];
self.title = [[selfclass]displayName];
// Set the background color for the window. The user will see the window's background color on the transition.
UIColor *backgroundColor = [UIColorcolorWithPatternImage:[UIImageimageNamed:@"pattern.png"]];
[UIApplicationsharedApplication].keyWindow.backgroundColor
= backgroundColor;
frontView = [[UIViewalloc]initWithFrame:self.view.bounds];
frontView.backgroundColor
= [UIColorcolorWithRed:0.345green:0.349blue:0.365alpha:1.000];
UIImageView *caLogoView = [[UIImageViewalloc]initWithImage:[UIImageimageNamed:@"caLogo.png"]];
caLogoView.frame =CGRectMake(70,80,
caLogoView.bounds.size.width, caLogoView.bounds.size.height);
[frontViewaddSubview:caLogoView];
UIImage *backImage = [UIImageimageNamed:@"backView.png"];
backView = [[UIImageViewalloc]initWithImage:backImage];
backView.userInteractionEnabled
= YES;
[self.viewaddSubview:backView];
[self.viewaddSubview:frontView];
displayingFrontView =YES;
UIGestureRecognizer *frontViewTapRecognizer = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(flipViews)];
UIGestureRecognizer *backViewTapRecognizer = [[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(flipViews)];
[frontViewaddGestureRecognizer:frontViewTapRecognizer];
[backViewaddGestureRecognizer:backViewTapRecognizer];
[frontViewTapRecognizerrelease];
[backViewTapRecognizerrelease];
}
- (void)flipViews {
[UIViewtransitionFromView:(displayingFrontView)
?frontView : backView
toView:(displayingFrontView)
? backView : frontView
duration:0.75
options:(displayingFrontView
?UIViewAnimationOptionTransitionFlipFromRight :UIViewAnimationOptionTransitionFlipFromLeft)
completion:^(BOOL finished) {
if (finished) {
displayingFrontView = !displayingFrontView;
}
}];
}
相关文章推荐
- 动画:UIKitAnimation 简单动画学习 iOS (一) 渐变 、 移动 、翻页、来回翻转 ——转载
- 动画:UIKitAnimation 简单动画----渐变 、 移动 、翻页、来回翻转
- Android基础-简单的动画实现 *补间动画 *透明度渐变 *旋转动画 *位移动画 *如果需要几个效果整合到一起,需要将所有效果全部放到set里
- IOS翻转动画(可来回切换图片)
- 【Android开发小记--7】动画--简单的button移动和图片3D翻转
- iOS学习之简单动画
- 【iOS学习笔记 15-11-06】简单自定义navigationcontroller push和pop动画效果
- ios学习笔记-05-渐变动画和button布局和kvc-kvo
- IOS 简单的动画自定义方法(旋转、移动、闪烁等)
- iOS(学习) 一个简单的动画效果
- iOS简单动画效果:闪烁、移动、旋转、路径、组合、
- ios学习笔记(三)简单动画
- ios学习笔记(三)简单动画
- IOS 简单的动画自定义方法(旋转、移动、闪烁等)
- iOS:CAAnimation动画集合:移动/旋转/缩放/弹簧/翻页效果/落叶动画
- 批量生成精灵,并实现拖拽精灵,和移动、翻转等简单动画
- iOS简单动画效果:闪烁、移动、旋转、路径、组合
- IOS 简单的动画自定义方法(旋转、移动、闪烁等)
- IOS 简单的动画自定义方法(旋转、移动、闪烁等)
- 我的iOS学习历程 - UISlider(简单的设置一组图片动画)