使用UIView类提供的功能来显示动画的例子
来源:互联网 发布:websocket for python 编辑:程序博客网 时间:2024/06/01 10:11
本文档版权归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
{
[myIVrelease];
[myButtonrelease];
[superdealloc];
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[superdidReceiveMemoryWarning];
// 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
{
[myIVrelease];
myIV = nil;
[myButtonrelease];
myButton = nil;
[superviewDidUnload];
// 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;
[UIViewbeginAnimations:@"aa"context:nil];
[UIViewsetAnimationCurve:UIViewAnimationCurveEaseIn];
[UIViewsetAnimationDuration:2.0];
[myIVsetFrame:frame];
[UIViewsetAnimationDelegate:self];
[UIViewsetAnimationDidStopSelector:@selector(viewExchangeAnimationDidStop:finished:context:)];
[UIViewcommitAnimations];
}
- (void) viewExchangeAnimationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
CGRect frame =myIV.frame;
frame.origin.y =25;
[UIViewbeginAnimations:@"aa"context:nil];
[UIViewsetAnimationCurve:UIViewAnimationCurveEaseOut];
[UIViewsetAnimationDuration:2.0];
[myIVsetFrame:frame];
[UIViewcommitAnimations];
}
@end
6.解释代码如下:
CGRect frame = myIV.frame;
frame.origin.y = 300;
[UIView beginAnimations:@"aa" context:nil];//开始一个动画
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];//设置动画先慢后快
[UIView setAnimationDuration:2.0];//设置动画持续2秒
[myIV setFrame:frame];//动画内容,从现有位置移动到frame指示的位置。
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(viewExchangeAnimationDidStop:finished:context:)];
//上面的两句话设置,当动画结束的时候,调用本类的viewExchangeAnimationDidStop:finished:context:函数
[UIView commitAnimations];//开始动画
其他的代码就不解释了,
7.例子代码
http://download.csdn.net/detail/NickTang/3690975
- 使用UIView类提供的功能来显示动画的例子
- IOS使用UIImageView显示gif动画的例子
- IOS使用UIImageView显示gif动画的例子
- IOS使用UIImageView显示gif动画的例子
- IOS使用UIImageView显示gif动画的例子
- IOS使用UIImageView显示gif动画的例子
- UI 动画之UIView动画的 四种 使用含有block的类方法 实现动画
- UIView+Genie神奇效果动画的使用
- UIView动画的属性
- UIView的动画总结
- UIView的动画
- UIView的动画
- uiview的animation动画
- UIView动画的Option
- UIView属性的动画
- UIView封装的动画
- UIView属性的动画
- UIView的简单动画
- 按键精灵,求ctrl+c按f1就可以了,ctrl+v按住f2就可以了,ctrl+enter按住f3就可以了的脚本
- Android编译问题:Only 64-bit build environments are supported beyond froyo/2.2
- 鸟哥的Linux私房菜10.15 档案与文件系统的压缩与打包
- LAPI.H
- 【转】用Oracle sqlldr导入文本文件TXT 总结
- 使用UIView类提供的功能来显示动画的例子
- LoadRunner字符串编码转换的函数lr_convert_string_encoding
- 鸟哥的Linux私房菜10.16 vim程序编辑器
- 鸟哥的Linux私房菜10.17 BASH
- 成长型中小企业信息化的现状分析
- lauxlib.c
- mac 下修改vi 使一个tab=4个空格
- 【转】Oracle导入文件
- 软件哲学研究什么?