- 浏览: 362812 次
文章分类
最新评论
-
lord_is_layuping:
...
PYQT4 + Python2.6 + eric4-4.2.2a的安装全过程 -
597272095:
3Q
Oracle客户端PL/SQL 中文乱码解决 -
lpluck08:
如果不是在git本地版本目录中执行的话,会有问题。到本地版本目 ...
git 中文文件名 乱码 mac -
aiove:
-API
分享到: 阿撒旦发撒旦发速度飞洒发
iOS开发开源项目推荐 -
Wallian_hua:
感谢,楼主的详细分析,对我的启发很大。。我也正在研究这方面的技 ...
[ZT]简单OCR实现原理
http://www.raywenderlich.com/1430/how-to-use-the-three20-photo-viewer
In this tutorial, we will cover how you can use Three20 to make a simple app that displays a set of photos just like the Photos app does – complete with flicking between photos, pinching to zoom, captions, and full screen mode. Best of all, because you’re using Three20, you get a lot of other great features built in such a built-in thumbnail viewer, being able to retrieve higher resolution images over the network, and caching the retrieved images locally! If you haven’t used Three20 before, you may wish to check out the Introduction to Three20 tutorial first. However, this tutorial is fairly self-contained, so it isn’t required! Create a new project in XCode by going to File\New Project, select Window-based Application, and make sure to choose iPhone for the product. Click Choose, and name the Project “PhotoViewer.” Next you need to get a copy of the three20 library. The best way to get the latest copy of three20 is to use the source control system “git.” If you do not already have this installed, you can download a Mac installer. Once you have git installed, follow the excellent instructions on the three20 web page for instructions on how to pull down the latest code and add it to your project. At the time of writing this post, there’s one additional step you need to take. The three20 projects are currently set to use iOS 3.0 as the Base SDK, but assuming you are using XCode 3.2.3, this SDK is no longer available. Therefore, you need to double click on each of the Three20 XCode projects in your Groups & Files list to open up the project, go to Project\Edit Project Settings in each Three20 project, and set the Base SDK to iPhone Device 4.0. Once you’ve done that, add the following to the top of PhotoViewerAppDelegate.h: #import “Three20/Three20.h” Then compile your project – if it works three20 has been successfully integrated and you can move onto the next step! To display a photo in the TTPhotoViewController, Three20 needs some information from our app. Specifically, it needs to know the size of the image, a URL for where to find the image, an optional caption for the image, and few other pieces of information. To give Three20 this information, we need to create a class representing our photos that implements the TTPhoto protocol. The definition for the TTPhoto protocol looks something like this: So we need to make sure our class has properties for the size of the image and any caption we want to display. We need to create a method to return a URL for the image. And we’ll need properties for a photoSource and index, but we’ll talk about what those mean later. A note about the method to retrieve a URL – note it takes a TTPhotoVersion parameter. This has values such as TTPhotoVersionSmall or TTPhotoVersionLarge, so we can return different URLs for images of different levels of quality. In fact that’s what we’ll do in this tutorial – we’ll include a couple small but low quality images embedded with the app, and a large but high quality image on a web server. So let’s create our own class that implements this protocol. Go to File\New File, choose Cocoa Touch Class\Objective-C class, make sure Subclass of NSObject is selected, and click Next. Name the new file Photo.m (and make sure also create Photo.h is selected), and click Finish. Replace Photo.h with the following: So basically we’re just creating a subclass of NSObject, but we implement the TTPhoto protocol. We create some properties for caption, photoSource, size, and index, since they’re required in the TTPhoto protocol, and some instance variables to back them up. We also create some instance variables to hold URLs to the three versions of the images we’re going to use for this tutorial – a “large” version, a “small” version, and a thumbnail version. Now move over to Photo.m and replace it with the following: We create a constructor for our Photo that we’ll use later, initializing everything to what’s passed in. Note we just initialize the index and photoSource to dummy values for now – they will be updated later after the constructor is called. The only method of real interest in this class is URLForVersion: here we examine the version passed in, and return the appropriate URL based on the version. Note we are not including a “medium quality” image in this tutorial, so we just return the URL for the large image in this case. By implementing this method, we’ll see that Three20 is smart enough to display the small image first (since it should load more quickly) and then follow up with retrieving the high quality image in the background and replacing the small image when its ready. Our next step is to create an object that the TTPhotoViewController can use to figure out what photos it should display. In Three20, we do that by creating an object that implements the TTPhotoSource protocol. The definition for the TTPhotoSource protocol looks something like this: So we need to return a title for the set of photos (used in the thumbnail view of the Photo View Controller), the number of photos to display (and the max index), and finally a method to return a TTPhoto at a particular index. padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; font-weight: inherit; font-style: inherit; font-size: 13px; font-family: inherit; vertical-align: baseline; li
How To Use the Three20 Photo Viewer
Adding Three20 To Your Project
Creating a TTPhoto Class
@protocol TTPhoto <NSObject, TTURLObject>
@property (nonatomic) CGSize size;
@property (nonatomic, copy) NSString* caption;
- (NSString*)URLForVersion:(TTPhotoVersion)version;
@property (nonatomic, assign) id<TTPhotoSource> photoSource;
@property (nonatomic) NSInteger index;
@end
#import <Foundation/Foundation.h>
#import <Three20/Three20.h>
@interface Photo : NSObject <TTPhoto> {
NSString *_caption;
NSString *_urlLarge;
NSString *_urlSmall;
NSString *_urlThumb;
id <TTPhotoSource> _photoSource;
CGSize _size;
NSInteger _index;
}
@property (nonatomic, copy) NSString *caption;
@property (nonatomic, copy) NSString *urlLarge;
@property (nonatomic, copy) NSString *urlSmall;
@property (nonatomic, copy) NSString *urlThumb;
@property (nonatomic, assign) id <TTPhotoSource> photoSource;
@property (nonatomic) CGSize size;
@property (nonatomic) NSInteger index;
- (id)initWithCaption:(NSString *)caption urlLarge:(NSString *)urlLarge urlSmall:(NSString *)urlSmall urlThumb:(NSString *)urlThumb size:(CGSize)size;
@end
#import "Photo.h"
@implementation Photo
@synthesize caption = _caption;
@synthesize urlLarge = _urlLarge;
@synthesize urlSmall = _urlSmall;
@synthesize urlThumb = _urlThumb;
@synthesize photoSource = _photoSource;
@synthesize size = _size;
@synthesize index = _index;
- (id)initWithCaption:(NSString *)caption urlLarge:(NSString *)urlLarge urlSmall:(NSString *)urlSmall urlThumb:(NSString *)urlThumb size:(CGSize)size {
if ((self = [super init])) {
self.caption = caption;
self.urlLarge = urlLarge;
self.urlSmall = urlSmall;
self.urlThumb = urlThumb;
self.size = size;
self.index = NSIntegerMax;
self.photoSource = nil;
}
return self;
}
- (void) dealloc {
self.caption = nil;
self.urlLarge = nil;
self.urlSmall = nil;
self.urlThumb = nil;
[super dealloc];
}
#pragma mark TTPhoto
- (NSString*)URLForVersion:(TTPhotoVersion)version {
switch (version) {
case TTPhotoVersionLarge:
return _urlLarge;
case TTPhotoVersionMedium:
return _urlLarge;
case TTPhotoVersionSmall:
return _urlSmall;
case TTPhotoVersionThumbnail:
return _urlThumb;
default:
return nil;
}
}
@end
Creating a Photo Source
@protocol TTPhotoSource <TTModel, TTURLObject>
@property (nonatomic, copy) NSString* title;
@property (nonatomic, readonly) NSInteger numberOfPhotos;
@property (nonatomic, readonly) NSInteger maxPhotoIndex;
- (id<TTPhoto>)photoAtIndex:(NSInteger)index;
@end
发表评论
-
[zt]iPhone开发中关于UIView Animation实现效果
2012-08-30 23:04 1365http://mobile.51cto.com/ipho ... -
Appletv3 到手试用 ,并推荐美剧一部
2012-06-04 21:20 2062一直也不知道 appletv 是干什么的,和同学聊起来,似乎他 ... -
mac 批量转换图片格式。
2012-02-05 11:42 1882mkdir jpegs; sips -s fo ... -
IOS 自带动画效果
2011-12-01 14:45 4049在ios view与view间切换的动画效果这篇文章中简单 ... -
[ZT]UITableView下拉刷新页面的实现
2011-12-01 14:02 2633UITableView下拉刷新页面的实现 以前 ... -
iOS的动画效果类型及实现方法
2011-12-01 14:00 4214iOS的动画效果类型及实现方法 ... -
[zt]UIImage图片的缩小与放大
2011-12-01 13:53 1500UIImage可以加载图片,但是我们想要得到一张缩小或放大 ... -
UIView内存释放问题
2011-12-01 11:30 1315UIView内存释放,之前一直以为把alloc的UIVie ... -
[zt]UIScrollView,点击、滑动翻页事件的区分
2011-11-29 10:00 3399UIScrollView,点击、滑动 ... -
iphone中的UITouch
2011-08-31 00:56 2120手指在屏幕上能达到的精度和鼠标指针有很大的不同。当用户触击 ... -
[ZT]UIView的剖析!
2011-08-27 18:49 2639http://blog.csdn.net/mengtnt/ ... -
CGAffineTransform相关函数
2011-07-05 00:24 8679CGAffineTransform rotation = ... -
xcode crash 查找 EXC_BAD_ACCESS 问题根源的方法
2011-06-28 17:49 10209xcode4 4.x EXC_BAD_ACCESS ... -
iOS开发开源项目推荐
2011-06-10 21:02 23641 tbxml xml解析的类库,只支持解析,不支持写, ... -
在ios应用程序中按目录管理资源
2011-06-10 21:00 5192在ios应用程序中按目录管理资源 在ios的 ... -
UIScrollView分页的实现
2011-06-06 17:14 6109UIScrollView分页的实现 UIScro ... -
编写简单的翻页效果
2011-05-30 21:46 1901http://marshal.easymorse ... -
UIPopoverController
2011-05-21 21:43 18011、初始化UIPopoverController ... -
iphone debug
2011-05-21 01:50 1100在 .pch中加入 #ifndef __OPTI ... -
国际化Iphone的应用程序名称
2011-01-17 13:31 1633http://www.voland.com.cn/iphone ...
相关推荐
How to use the Bayes Net Toolbox? This documentation was last updated on 29 October 2007.
The tool that you need is Adobe Photoshop and the book you need to learn all about it is How to Use Adobe Photoshop CS 2. Visually step through the process of creating images, manipulating them and ...
You should ensure that the server's public keys are loaded by the client as described in How to use SFTP (with server validation - known hosts), or you may want to switch off server validation to get ...
Simple application that shows how to use the Data Control to connect to the Biblio.mdb database and display all authors in the Authors table.
How to use projector
How to Use Objects Code and Concepts Holger Gast
this article introduces how to use awk in linux
How to use the IPMI Spec Manual.doc.配合ipmiv2协议使用
How to Use the ALV Form Elements for Events.pdf
How to use epoll A complete example in C How to use epoll A complete example in C How to use epoll A complete example in C How to use epoll A complete example in C
This is an example of how to use the Common Dialog. This demonstrates most of the event procedures of the CM Dialog control.
This is a small project showing how to use the Sleep API call from within your program to pause for a set period of time. Its much better than looping round as it uses very little CPU time
You don't need any NFS windows client to access the NFS remote export, you can just use microsoft explorer. The current version doesn't support NFS v4.1 yet. Moved to ...
IBM How to use Seven Keys To Success.
It contains as following: ...2. how to use message box to launch the Help document. 3. how to make the title of the messsage box to align right. 4. how to show the Help button in the message box.
How to Use Objects will help you gain that understanding, so you can write code that works exceptionally well in the real world. Author Holger Gast focuses on the concepts that have repeatedly ...
HOW TO USE SDRAM ,sdr sdram的用户手册,比datasheet讲述的详细!
how to use array in jaba
Practice exercises throughout the book give students stimulus material to use as they practice to achieve mastery of the program. Thoroughly field-tested; your students are certain to appreciate this ...