IOS 开发之UIView动画的实例详解

 更新时间:2017年07月15日 16:03:14   作者:Hi_Aaron  
这篇文章主要介绍了IOS 开发之UIView动画的实例详解的相关资料,需要的朋友可以参考下

IOS 动画实例详解

iOS动画的实现方式多种多样,这里就只记录一下 beginAnimations:context 。

在你调用 beginAnimations:context:方法来启动一个动画后,动画并不会立即被执行,直 到你调用 UIView 类的 commitAnimations 类方法。你对一个视图对象执行的介于 beginAnimations:context:方法跟 commitAnimations方法之间的操作(例如移动)会在 commitAnimations 被执行后才会生效 。

实现效果图:

代码很简单,直接贴了,如下:

// 
// ViewController.m 
// Graphics 
// 
// Created by aaron on 14b-5-29. 
// Copyright (c) 2014年 The Technology Studio. All rights reserved. 
// 
 
#import "ViewController.h" 
 
@interface ViewController () 
@property(nonatomic,strong) UIImageView *imageView1; 
@property(nonatomic,strong) UIImageView *imageView2; 
 
@end 
 
@implementation ViewController 
 
- (void)viewDidLoad 
{ 
  [super viewDidLoad]; 
   
  UIImage *image = [UIImage imageNamed:@"1.png"]; 
  self.imageView1 = [[UIImageView alloc] initWithImage:image]; 
  self.imageView2 = [[UIImageView alloc] initWithImage:image]; 
  [self.imageView1 setFrame:CGRectMake(0.0f, 
                     0.0f, 
                     100.0f, 
                     100.0f)]; 
   
  [self.imageView2 setFrame:CGRectMake(220.0f, 
                     350.0f, 
                     100.0f, 
                     100.0f)]; 
  [self.view addSubview:self.imageView1]; 
  [self.view addSubview:self.imageView2]; 
   
//  [self startTopLeftImageViewAnimation]; 
//  [self startBottomRightViewAnimationAfterDelay:2]; 
  [self affineTransformScaleAnimation]; 
  [self affineTransformRotateAnimation]; 
   
} 
 
//imageView2 animation 
-(void)startTopLeftImageViewAnimation{ 
  [self.imageView1 setFrame:CGRectMake(0.0f, 
                     0.0f, 
                     100.0f, 
                     100.0f)]; 
  [self.imageView1 setAlpha:1.0f]; 
  [UIView beginAnimations:@"imageView1Animation" context:(__bridge void*)self.imageView1]; 
  [UIView setAnimationDuration:3.0f]; 
  [UIView setAnimationDelegate:self]; 
  [UIView setAnimationDidStopSelector:@selector(imageViewDidStop:finished:context:)]; 
  [self.imageView1 setFrame:CGRectMake(220.0f, 350.0f, 100.0f, 100.0f)]; 
  [self.imageView1 setAlpha:0.0f]; 
  [UIView commitAnimations]; 
} 
 
-(void)imageViewDidStop:(NSString*)paramAnimationID finished:(NSNumber*)paramFinished context:(void*)paramContext{ 
  NSLog(@"AnimationID = %@\n",paramAnimationID); 
  UIImageView *contextImageView = (__bridge UIImageView *)(paramContext); 
  NSLog(@"contextImageView = %@",contextImageView); 
  [contextImageView removeFromSuperview]; 
} 
 
 
//imageView2 animation 
-(void)startBottomRightViewAnimationAfterDelay:(CGFloat)paramDelay{ 
  [self.imageView2 setFrame:CGRectMake(220.0f, 
                     350.0f, 
                     100.0f, 
                     100.0f)]; 
  [self.imageView2 setAlpha:1.0f]; 
  [UIView beginAnimations:@"imageView2Animation" context:(__bridge voidvoid *)(self.imageView2)]; 
  [UIView setAnimationDuration:3.0f]; 
  [UIView setAnimationDelay:paramDelay]; 
  [UIView setAnimationDelegate:self]; 
  [UIView setAnimationDidStopSelector:@selector(imageViewDidStop:finished:context:)]; 
  [self.imageView2 setFrame:CGRectMake(0.0f, 0.0f, 100.0f, 100.0f)]; 
  [self.imageView2 setAlpha:0.0f]; 
  [UIView commitAnimations]; 
} 
 
 
//imageView1 AffineTransformScale animation 
-(void)affineTransformScaleAnimation{ 
  self.imageView1.center = self.view.center; 
  self.imageView1.transform = CGAffineTransformIdentity; 
  [UIView beginAnimations:nil context:NULL]; 
  [UIView setAnimationDuration:5.0f]; 
  self.imageView1.transform = CGAffineTransformMakeScale(2.0f, 2.0f); 
  [self.imageView1 setAlpha:0.0f]; 
  [UIView commitAnimations]; 
} 
 
//imageView2 AffineTransformRotate animation 
-(void)affineTransformRotateAnimation{ 
  self.imageView2.center = self.view.center; 
  [UIView beginAnimations:@"clockwiseAnimation" context:NULL]; 
  [UIView setAnimationDuration:5.0f]; 
  [UIView setAnimationDelegate:self]; 
  [UIView setAnimationDidStopSelector:@selector(clockwiseRotationStopped:finished:context:)]; 
  self.imageView2.transform = CGAffineTransformMakeRotation(90.0f*M_PI/180.f); 
  [UIView commitAnimations]; 
} 
 
 
-(void)clockwiseRotationStopped:(NSString*)paramAnimationID finished:(NSNumber*)paramFinished context:(void*)paramContext{ 
  [UIView beginAnimations:@"counterclockwiseAnimation" context:NULL]; 
  [UIView setAnimationDuration:5.0f]; 
  self.imageView2.transform = CGAffineTransformIdentity; 
  [UIView commitAnimations]; 
} 
 
@end 

以上就是关于IOS动画开发的实例,本站对于IOS 开发还有很多教程,大家可以搜索查阅!

相关文章

  • iOS开发实现随机图片验证码封装

    iOS开发实现随机图片验证码封装

    这篇文章主要介绍了iOS开发实现随机图片验证码封装,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-08-08
  • iOS实现波浪效果

    iOS实现波浪效果

    这篇文章主要为大家详细介绍了iOS实现波浪效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-05-05
  • IOS TextFiled与TextView 键盘的收起以及处理键盘遮挡

    IOS TextFiled与TextView 键盘的收起以及处理键盘遮挡

    这篇文章主要介绍了IOS TextFiled与TextView 键盘的收起以及处理键盘遮挡的相关资料,需要的朋友可以参考下
    2016-12-12
  • ios app重提提交审核流程

    ios app重提提交审核流程

    本篇文章给大家讲述了在APP第一次没有审核通过后,重新提交的流程和注意的地方,学习一下吧。
    2017-12-12
  • iOS实现UITableView左滑删除复制即用功能

    iOS实现UITableView左滑删除复制即用功能

    这篇文章主要介绍了iOS实现UITableView左滑删除复制即用功能,在项目开发中经常会用到这样的需求,下面小编把实现代码分享给大家,需要的朋友可以参考下
    2017-09-09
  • iOS 底部按钮和应用图标显示未读消息(带数字)

    iOS 底部按钮和应用图标显示未读消息(带数字)

    本文主要介绍了iOS 底部按钮和应用图标显示未读消息的相关知识。具有很好的参考价值。下面跟着小编一起来看下吧
    2017-04-04
  • iOS中排列组合算法的使用小结

    iOS中排列组合算法的使用小结

    这篇文章主要给大家介绍了关于iOS中排列组合算法使用的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2018-09-09
  • iOS实现音频进度条效果

    iOS实现音频进度条效果

    这篇文章主要介绍了ios实现音频进度条效果,本文写了一个小demo通过实例代码相结合的形式给大家详细介绍,需要的朋友可以参考下
    2018-10-10
  • iOS开发项目- 基于WebSocket的聊天通讯(1)

    iOS开发项目- 基于WebSocket的聊天通讯(1)

    这篇文章主要介绍了iOS开发项目- 基于WebSocket的聊天通讯,WebSocket是web通信方式的一种,有需要的可以了解一下。
    2016-11-11
  • iOS中lebel特殊字符的自动换行问题解决

    iOS中lebel特殊字符的自动换行问题解决

    这篇文章主要给大家介绍了关于iOS中lebel特殊字符的实现不自动换行的相关资料,文中通过示例代码介绍的非常详细,对大家学习iOS具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧。
    2017-10-10

最新评论