本文档版权归NickTang所有,没有本人书面或电子邮件允许,不许转载,摘录,发表。多谢!
上一个文档,我演示了timer的使用,并且形成了一个动画,但是这个动画可扩展性不好,我们需要更好的动画实现技术,这里UIView类提供了一些基本的功能。
1.新建一个view-based
Application.(在iOS5中是Single View Application)
2.加入一个小的图片,我用的是一个circle.png,长和宽都不要大于100.
3.在viewcontroller.xib上面做如下布局
4. ViewController.h文件如下:
@interface subViewAnimationViewController :
UIViewController {
IBOutlet UIButton *myButton;
IBOutlet UIImageView *myIV;
}
- (IBAction)startAnimation:(id)sender;
@end
5.
ViewController.m文件如下:
@implementation subViewAnimationViewController
- (void)dealloc
{
[myIV
release];
[myButton
release];
[super
dealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super
didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
}
*/
- (void)viewDidUnload
{
[myIV
release];
myIV = nil;
[myButton
release];
myButton = nil;
[super
viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (IBAction)startAnimation:(id)sender {
CGRect frame = myIV.frame;
frame.origin.y =
300;
[UIView
beginAnimations:@"aa"
context:nil];
[UIView
setAnimationCurve:UIViewAnimationCurveEaseIn];
[UIView
setAnimationDuration:2.0];
[myIV
setFrame:frame];
[UIView
setAnimationDelegate:self];
[UIView
setAnimationDidStopSelector:@selector(viewExchangeAnimationDidStop:finished:context:)];
[UIView
commitAnimations];
}
- (void) viewExchangeAnimationDidStop:(NSString *)animationID finished:(NSNumber *)finished
context:(void *)context {
CGRect frame =
myIV.frame;
frame.origin.y =
25;
[UIView
beginAnimations:@"aa"
context:nil];
[UIView
setAnimationCurve:UIViewAnimationCurveEaseOut];
[UIView
setAnimationDuration:2.0];
[myIV
setFrame:frame];
[UIView
commitAnimations];
}
@end
6.解释代码如下:
CGRectframe =myIV.frame;
frame.origin.y=300;
[UIViewbeginAnimations:@"aa"context:nil];//开始一个动画
[UIViewsetAnimationCurve:UIViewAnimationCurveEaseIn];//设置动画先慢后快
[UIViewsetAnimationDuration:2.0];//设置动画持续2秒
[myIVsetFrame:frame];//动画内容,从现有位置移动到frame指示的位置。
[UIViewsetAnimationDelegate:self];
[UIViewsetAnimationDidStopSelector:@selector(viewExchangeAnimationDidStop:finished:context:)];
//上面的两句话设置,当动画结束的时候,调用本类的viewExchangeAnimationDidStop:finished:context:函数
[UIViewcommitAnimations];//开始动画
其他的代码就不解释了,
7.例子代码
http://download.csdn.net/detail/NickTang/3690975
分享到:
相关推荐
UIView+动画属性 这个对UIView块动画的扩展允许你实现自己的UIView子类的...例子您的UIView子类具有自定义动画属性: @implementation ANPCornerView@dynamic cornerRadius;- ( CGFloat ) cornerRadius { return self.
用uiview提供的动画函数来实现界面的转换,为我的博客的提供例子代码。
BRY串行动画队列使用您已经熟悉和喜爱的相同 API,在不阻塞主线程的情况下连续执行 UIView 动画。安装当然,通过 : pod "BRYSerialAnimationQueue"为什么? 该类的主要目标是使执行基于事件的动画变得容易(例如,...
iOS基本动画/关键帧动画/利用缓动函数实现物理动画效果 先说下基本动画部分 基本动画部分比较简单, 但能实现的动画效果也很局限 使用方法大致为: #1. 创建原始UI或者画面 #2. 创建CABasicAnimation实例, 并设置...
基于UIStackView的类,可对其更改进行动画处理。 当前仅支持垂直动画。 例子 克隆仓库,然后打开Carthage Project/AnimatableStackView.xcodeproj GIF动画 安装 迦太基 请检查 购物车文件: github "APUtils/...
用法(举例) 一个常见的例子是使用 CLAutoLayoutTemplates 为视图的框架更改设置动画。 例如,假设您有一个按钮myButton ,其初始位置使用自动布局声明,并且您希望按钮移动到不同的位置,您也希望使用自动布局声明...
iOS 动画必不可少的书籍,包含UIView动画,CALayer层动画,粒子动画,3D动画,转场动画等,其中的动画效果都使用清晰的例子进行演示易于学习
源码ClickZanButton,这个...ZanButton.swift 这个文件封装了整个点赞的动画过程,直接找一个UIView设置成这个类就可以用了. 具体的可以看项目的注释以及例子. PS 带箭头的PopView还没有实现,应该不难.下次再继续完善
实现了只用UIView或CATransition的简单动画,也实现了利用关键帧CAKeyframeAnimation的复杂动画,各举了几个例子。
3.6 重新显示网页36 3.6.1 gmail iphone页面36 3.6.2 facebook iphone页面37 3.7 支持非iphone用户38 3.8 小结39 第4章 高级webkit和文本web应用程序40 4.1 webkit简介40 4.1.1 新的html元素41 ...
这是iOS中动画绝佳的例子,利用放射变换和uiview,制作出非常友好的动画效果。同时代码写的非常优雅(very elegant!!)
用你一直想要的动画来思考 UICollectionView。 工作正在进行中。例子 let feedView = FeedView ( frame : CGRectMake ( 0 , 0 , self . view . frame . size . width , self . view . frame . size . height ))feed...
实现各种页面过渡切换效果。前4种是UIView,后面都是 Core Animation。 下面8种是传说中的私有API(作者测试过,能通过审核,请放心使用)。所有效果整合到一个例子里,代码较清晰,适合新手阅读。
使用 UIView 动画,在单击主按钮时,我们将其他按钮上移以将它们放置在主按钮上方。 此外,我们旋转主按钮(它是一个 + 图标)使其看起来像一个 x 图标(关闭)。截图默认状态: 菜单打开状态:
通过特征 :light_bulb: 基于速度和卡片位置的高级滑动识别 :light_bulb: 手动和程序操作 :light_bulb: 平滑的卡片叠加视图过渡 :light_bulb: 流畅且可自定义的动画 :light_bulb: 使用数据源模式动态加载卡例子要...
表格单元动画 示例如何在表格视图单元格上使用 UIViewAnimation 如何使用 func tableView ( tableView : UITableView, willDisplayCell cell : UITableViewCell, forRowAtIndexPath indexPath : NSIndexPath) { ...
将视图的类从UIView更改为HeartLoadingView 以编程方式: let heartLoadingView = HeartLoadingView(frame: yourFrame) 客制化 进度等级(0 .. <1) heartLoadingView.progress = 0.5 振幅 heartLoadingView....
要使用提供的类,请import DSColorPicker 。 展示拾色器 创建Grid或Circle DSColorPickerView之后,调用show(animated:completion:) 。 默认情况下,演示文稿是动画的,完成处理程序不执行任何操作。 例子: 在...