OpenFlow(效果图)中文实用详解
2012-01-08 00:21
134 查看
当用户界面需要按页面显示图片时,使用OpenFlow库提供的功能,将要显示的用户界面图片分页进行显示会使编程工作变得非常快捷。该库提供了与OS X桌面Finder程序相同的视觉效果,如图3-46所示就是一个使用OpenFlow库逐页进行图片显示的程序,用户按下屏幕即可进行左右滚动显示,双击图片即可对当前显示的图片进行选取操作。
// RootViewController.m
程序在视图控制器的viewDidAppear()中使用refreshCoverFlow()函数初始化OpenFlow库,通过setNumberOfImages()函数设置图片数量,代码如下。
- (void)refreshCoverFlow{
CGRect bounds = [[UIScreen mainScreen]bounds];
AFOpenFlowView *coverFlowView =(AFOpenFlowView*)[self.view viewWithTag:kTagCoverflow];
if(coverFlowView != nil)
[coverFlowView removeFromSuperview];
coverFlowView = [[AFOpenFlowView alloc]initWithFrame:CGRectMake(0, -30, bounds.size.width,COVERFLOWHEIGHT)];
coverFlowView.dataSource = self;
coverFlowView.viewDelegate = self;
coverFlowView.defaultImage = [selfdefaultImage];
coverFlowView.tag = kTagCoverflow;
[self.view addSubview:coverFlowView];
NSInteger count = [self numberOfAnimals];
[coverFlowView setNumberOfImages:count];
//...
[coverFlowView release];
}
并在loadView()中初始化图片,将图片从资源中加载并保存在一个NSMutableArray类型的变量imageArray中,代码如下。
- (BOOL)doAddAnimal:(NSString *)name Image:(NSString*)imageName{
UIImage *image = [UIImage imageNamed:imageName];
if(image == nil) return FALSE;
CGSize size = CGSizeMake(179,208);
[imageArray addObject:[self resizeImage:imagescaledToSize:size]];
return TRUE;
}
在OpenFlow库的requestImageForIndexdelegate方法中直接通过NSMutableArray的索引作为OpenFlow库的图片索引,并通过该索引设置和获取具体图片,代码如下。
// PageViewController.m
- (void)openFlowView:(AFOpenFlowView *)openFlowViewrequestImageForIndex: (int)index{
UIImage *image = [imageArrayobjectAtIndex:index];
[openFlowView setImage:imageforIndex:index];
}
笔者在OpenFlow库AFOpenFlowView.m文件的touchesEnded()函数中增加了双击回调接口,以便在用户双击图片时通知库的调用者,代码如下。
//AFOpenFlowView.m
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
if(((UITouch *)[touches anyObject]).tapCount ==2){
if ([self.viewDelegate respondsToSelector:@selector(openFlowView:coverViewDoubleClick:)])
[self.viewDelegateopenFlowView:self coverViewDoubleClick:selectedCoverView.number];
}
[supertouchesEnded:touches withEvent:event];
}
库的调用者RootViewController类通过接口函数coverViewDoubleClick()即可处理用户双击事件,代码如下。
- (void)openFlowView:(AFOpenFlowView *)openFlowViewcoverViewDoubleClick:(int)index{
NSLog(@"coverViewDoubleClick called!");
[self showPaintingViewController];}
// RootViewController.m
程序在视图控制器的viewDidAppear()中使用refreshCoverFlow()函数初始化OpenFlow库,通过setNumberOfImages()函数设置图片数量,代码如下。
- (void)refreshCoverFlow{
CGRect bounds = [[UIScreen mainScreen]bounds];
AFOpenFlowView *coverFlowView =(AFOpenFlowView*)[self.view viewWithTag:kTagCoverflow];
if(coverFlowView != nil)
[coverFlowView removeFromSuperview];
coverFlowView = [[AFOpenFlowView alloc]initWithFrame:CGRectMake(0, -30, bounds.size.width,COVERFLOWHEIGHT)];
coverFlowView.dataSource = self;
coverFlowView.viewDelegate = self;
coverFlowView.defaultImage = [selfdefaultImage];
coverFlowView.tag = kTagCoverflow;
[self.view addSubview:coverFlowView];
NSInteger count = [self numberOfAnimals];
[coverFlowView setNumberOfImages:count];
//...
[coverFlowView release];
}
并在loadView()中初始化图片,将图片从资源中加载并保存在一个NSMutableArray类型的变量imageArray中,代码如下。
- (BOOL)doAddAnimal:(NSString *)name Image:(NSString*)imageName{
UIImage *image = [UIImage imageNamed:imageName];
if(image == nil) return FALSE;
CGSize size = CGSizeMake(179,208);
[imageArray addObject:[self resizeImage:imagescaledToSize:size]];
return TRUE;
}
在OpenFlow库的requestImageForIndexdelegate方法中直接通过NSMutableArray的索引作为OpenFlow库的图片索引,并通过该索引设置和获取具体图片,代码如下。
// PageViewController.m
- (void)openFlowView:(AFOpenFlowView *)openFlowViewrequestImageForIndex: (int)index{
UIImage *image = [imageArrayobjectAtIndex:index];
[openFlowView setImage:imageforIndex:index];
}
笔者在OpenFlow库AFOpenFlowView.m文件的touchesEnded()函数中增加了双击回调接口,以便在用户双击图片时通知库的调用者,代码如下。
//AFOpenFlowView.m
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
if(((UITouch *)[touches anyObject]).tapCount ==2){
if ([self.viewDelegate respondsToSelector:@selector(openFlowView:coverViewDoubleClick:)])
[self.viewDelegateopenFlowView:self coverViewDoubleClick:selectedCoverView.number];
}
[supertouchesEnded:touches withEvent:event];
}
库的调用者RootViewController类通过接口函数coverViewDoubleClick()即可处理用户双击事件,代码如下。
- (void)openFlowView:(AFOpenFlowView *)openFlowViewcoverViewDoubleClick:(int)index{
NSLog(@"coverViewDoubleClick called!");
[self showPaintingViewController];}
相关文章推荐
- 最实用DOS命令参数的中文详解
- 微信开发中文字交互项目详解
- Nginx配置文件nginx.conf中文详解(总结)
- MySQL配置文件my.cnf中文详解
- 如何正确且高效地中文汉化Spyder 2 或 Spyder3(图文详解)(博主推荐)
- js中几种实用的跨域方法原理详解
- EasyPR--中文开源车牌识别系统 开发详解(1)
- JAVA中文字符乱码解决详解
- DRUID连接池的实用 配置详解
- PHP的服务器Apache中httpd.conf 的中文详解
- Nginx配置文件nginx.conf中文详解(总结)
- js中几种实用的跨域方法原理详解
- JSON取值(key是中文或者数字)方式详解
- libcurl中curl_easy_setopt()和curl_easy_perform()函数使用中文详解
- SIP协议详解(中文)-3
- JSP中文乱码问题详解
- Java 判断字符串中是否包含中文的实例详解
- DRUID连接池的实用 配置详解
- Jquery UI dialog 详解 (中文)