从本篇开始不再详细介绍每一步操作,而只介绍一些关键操作及展示核心代码和代码解释。
实现的功能:1)演示一个简单的动画效果,动态加载图片。2)点击屏幕时重新加载动画。
关键词:Animation 动画 动态加载图片
1、新建视图控制器ImageViewController(不带xib),作为根视图控制器,ImageViewController.h如下:
#import <UIKit/UIKit.h>
@interface ImageViewController : UIViewController
@property(strong,nonatomic)UIImageView *imageView;
@property(strong,nonatomic)UIImage *desktop;
-(void)loadImage;
@end
ImageViewController.m如下:
#import "ImageViewController.h"
@implementation ImageViewController
@synthesize imageView;
@synthesize desktop;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)loadView
{
// If you create your views manually, you MUST override this method and use it to create your views.
// If you use Interface Builder to create your views, then you must NOT override this method.
NSLog(@"loadView");
UIView *view = [[ UIView alloc] initWithFrame:[ UIScreen
mainScreen].applicationFrame] ;
UIColor *bgColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1.0];
[view setBackgroundColor:(bgColor)];
self.view = view;
desktop = [UIImage imageNamed:@"desktop.png"];
[self performSelector:@selector(loadImage) withObject:nil afterDelay:0.1];
}
-(void)loadImage{
if(imageView!=nil){
[imageView removeFromSuperview];
}
//初始时,将imageView的宽度设置为0,这样就隐藏起来了
imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 0, desktop.size.height)];
[imageView setImage:desktop];
[self.view addSubview:imageView];
//设置动画效果
CGContextRef context = UIGraphicsGetCurrentContext();
//开始播放动画
[UIView beginAnimations:nil context:context];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
//[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
//[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
//[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[UIView setAnimationDuration:1.5];
//imageView最终的宽度为desktop.size.width
[imageView setFrame:CGRectMake(0, 0, desktop.size.width, desktop.size.height)];
[UIView commitAnimations];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self loadImage];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
imageView = nil;
desktop = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
@end
2、运行效果是图片从左至右慢慢显示出来,如下,
[img]
[/img]
- 大小: 241.9 KB
分享到:
相关推荐
Iphone开发系列源码——Image图片缩放随着手指Iphone开发系列源码——Image图片缩放随着手指Iphone开发系列源码——Image图片缩放随着手指Iphone开发系列源码——Image图片缩放随着手指Iphone开发系列源码——Image...
Iphone开发系列源码——Iphone主题源码Iphone开发系列源码——Iphone主题源码Iphone开发系列源码——Iphone主题源码Iphone开发系列源码——Iphone主题源码Iphone开发系列源码——Iphone主题源码Iphone开发系列源码...
Iphone开发系列源码——iPhone版Wordpress源代码Iphone开发系列源码——iPhone版Wordpress源代码Iphone开发系列源码——iPhone版Wordpress源代码Iphone开发系列源码——iPhone版Wordpress源代码Iphone开发系列源码...
Iphone开发系列源码——多功能播放器源码Iphone开发系列源码——多功能播放器源码Iphone开发系列源码——多功能播放器源码Iphone开发系列源码——多功能播放器源码Iphone开发系列源码——多功能播放器源码Iphone开发...
Iphone开发系列源码——星级评价实现代码Iphone开发系列源码——星级评价实现代码Iphone开发系列源码——星级评价实现代码Iphone开发系列源码——星级评价实现代码Iphone开发系列源码——星级评价实现代码Iphone开发...
Iphone开发系列源码——图表和报表的统计功能Iphone开发系列源码——图表和报表的统计功能Iphone开发系列源码——图表和报表的统计功能Iphone开发系列源码——图表和报表的统计功能Iphone开发系列源码——图表和报表...
Iphone开发系列源码——公交线路查询项目完整源码Iphone开发系列源码——公交线路查询项目完整源码Iphone开发系列源码——公交线路查询项目完整源码Iphone开发系列源码——公交线路查询项目完整源码Iphone开发系列...
Iphone开发系列源码——长按实现图标抖动和删除的代码Iphone开发系列源码——长按实现图标抖动和删除的代码Iphone开发系列源码——长按实现图标抖动和删除的代码Iphone开发系列源码——长按实现图标抖动和删除的代码...
iphone开发 动画类库 源代码 直接导入程序使用 旋转 翻滚 渐变
本书面向新的iPhone 开发人员,他们马上要开发实际项目,但面对着一个全新的SDK。虽然每位程 序员创建表格的目标和经验并不相同,但大多数人都需要在其开发工作中解决类似的任务:如何构建表格, 如何创建安全的密钥...
本书面向新的iPhone 开发人员,他们马上要开发实际项目,但面对着一个全新的SDK。虽然每位程 序员创建表格的目标和经验并不相同,但大多数人都需要在其开发工作中解决类似的任务:如何构建表格, 如何创建安全的密钥...
本书面向新的iPhone 开发人员,他们马上要开发实际项目,但面对着一个全新的SDK。虽然每位程 序员创建表格的目标和经验并不相同,但大多数人都需要在其开发工作中解决类似的任务:如何构建表格, 如何创建安全的密钥...
iPhone与iPad开发实战——精通iOS开发1.rar
iPhone与iPad开发实战——精通iOS开发2.rar
一款使用html5 svg技术制作的线条动态绘制iphone边框动画效果,页面中先是用线条动态绘制出iphone的轮廓,然后再显示iphone图片,效果十分华丽。
9种移动开发专用的HTML5加载条动画效果,纯CSS3实现的网页进度条特效,支持HTML5的浏览器就能完美支持,Android手机、iPhone都可以很好的支持,这些进度条每一款的风格都不相同,都带有动画效果,而且没有使用任何的...
此代码是IOS平台用xcode实现文字书写效果,以及动画。
安卓Android源码——仿Iphone抖动效果ShakeIcon.zip