现在的位置: 首页 > 综合 > 正文

动画:UIKitAnimation 简单动画学习 iOS (一) 渐变 、 移动 、翻页、来回翻转

2018年05月26日 ⁄ 综合 ⁄ 共 3154字 ⁄ 字号 评论关闭

转载请说明(谢谢)

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;

}

}];

}

抱歉!评论已关闭.