资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

IOS开发之UIView动画的示例分析-创新互联

这篇文章将为大家详细讲解有关IOS开发之UIView动画的示例分析,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

网站建设哪家好,找创新互联公司!专注于网页设计、网站建设、微信开发、微信小程序、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了延平免费建站欢迎大家使用!

IOS 动画实例详解

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

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

实现效果图:

IOS开发之UIView动画的示例分析IOS开发之UIView动画的示例分析

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

// 
// 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开发之UIView动画的示例分析”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网页题目:IOS开发之UIView动画的示例分析-创新互联
新闻来源:http://cdkjz.cn/article/dehicc.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220