iphone Three20如何添加到工程,以及如何添加删除图片的按钮。
2011-12-23 10:02
447 查看
最近由于项目需要,需要做一个相册查看器来查看项目截图的图片。于是发现Three20的功能很强大,有自带的相册功能,于是就将其引用到工程里头来。
首先是要下载three20并安装到工程里头。
如果是想手动将three20添加到xcode4.2的话,可参照此链接:添加three20到xcode4.2教程
如果想通过指令来将three20添加到xcode的话,可参照此链接通过指令将three20添加到xcode教程
通过指令来将three20添加到xcdoe时,操作比较快速。
但有几点需要注意。
1.尽量让下载的three20 与工程处于同一个目录,这样在后续的设置中会比较方便。
2.如果PROJECT的名称与TARGETS的名称不一样的话,那通过指令执行时,需要执行如下指令。
3.接着按这些步骤把相册添加到自己的工程中去,将图片相册添加到工程。
3,如何在现有的程序中单击某一按钮,然后导航到three20的相册中。代码如下:如果想进一步的了解导航具体情况,那么可以参照此链接。导航具体教程
- (IBAction)viewPhoto:(id)sender
{
NSLog(@"%@",currentImageName);
NSLog(@"%d",[currentImageName retainCount]);
[[TTURLRequestQueue mainQueue] setMaxContentLength:0];
TTNavigator *navigator = [TTNavigator navigator];
navigator.window = [UIApplication sharedApplication].keyWindow;
TTURLMap *map = navigator.URLMap;
[map from:@"tt://appPhotos" toSharedViewController:[PhotoViewController class]];
[navigator openURLAction:[TTURLAction actionWithURLPath:@"tt://appPhotos"]];
}
4,如果想从相册返回到原工程,可以在PhotoViewController.h 添加如下代码:
4.1添加返回按钮到导航栏
- (void) viewDidLoad {
UIBarButtonItem *listViewBackBtn = [[UIBarButtonItem alloc] initWithTitle:@"test"
style:UIBarButtonItemStylePlain
target:self
action:@selector(GoBack:)];
self.navigationItem.leftBarButtonItem = listViewBackBtn;
self.navigationItem.hidesBackButton = YES;
[listViewBackBtn release];
self.photoSource = [PhotoSet samplePhotoSet];
self.centerPhotoIndex = currentCaptureIndex; }
4.2添加返回按钮事件
//返回到视频观看页面
-(void) GoBack:(id)sender{
[[TTNavigator navigator] removeAllViewControllers];
}
5.如何在相册中添加删除事件。
5.1具体添加删除按钮以及事件可以参照此教程添加删除事件 、添加删除事件2
5.2 删除后的图片中兴的事件。如下:
//删除图片
- (void)deletePhotoAtIndex:(NSInteger)index
{
NSMutableArray *muPhotos = [PhotoSet samplePhotoSet].photos;
Photo *removePhoto = [muPhotos objectAtIndex:index];
NSString *removePhotoName = removePhoto.caption;
[self removePhotosOfDocuments:index removePhotoName:removePhotoName];
// [muPhotos removeObjectAtIndex:index];
self.photoSource = [PhotoSet samplePhotoSet];
self.centerPhotoIndex = index;
}
- (void) removePhotosOfDocuments:(NSInteger)index removePhotoName:(NSString *) removePhotoName
{
NSFileManager *fileManage = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask , YES) ;
NSString *documentDirectory = [paths objectAtIndex:0];
NSString *bigImagePath = [documentDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"BigImage/%@",removePhotoName]];
NSString *smallImagePath = [documentDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"SmallImage/small_%@",removePhotoName]];
NSError *error = nil;
[fileManage removeItemAtPath:bigImagePath error:&error];
[fileManage removeItemAtPath:smallImagePath error:&error];}
5.3如果上传某一张图片,然后返回照片缩略图查看器,结果发现照片缩略图查看器中被删除的图片还在,这时需要修改TTPhotoViewController这个类的方法:红色部分为新添加的。这样才能保持相册缩略图的同步。
TTPhotoViewController
- (void)showThumbnails {
NSString* URL = [self URLForThumbnails];
if (!_thumbsController) {
if (URL) {
// The photo source has a URL mapping in TTURLMap, so we use that to show the thumbs
NSDictionary* query = [NSDictionary dictionaryWithObject:self forKey:@"delegate"];
TTBaseNavigator* navigator = [TTBaseNavigator navigatorForView:self.view];
_thumbsController = [[navigator viewControllerForURL:URL query:query] retain];
[navigator.URLMap setObject:_thumbsController forURL:URL];
} else {
// The photo source had no URL mapping in TTURLMap, so we let the subclass show the thumbs
_thumbsController = [[self createThumbsViewController] retain];
_thumbsController.photoSource = _photoSource;
}
}
if (URL) {
TTOpenURLFromView(URL, self.view);
} else {
if ([self.navigationController isKindOfClass:[TTNavigationController class]]) {
_thumbsController.photoSource = _photoSource;
[(TTNavigationController*)self.navigationController
pushViewController: _thumbsController
animatedWithTransition: UIViewAnimationTransitionCurlDown];
} else {
_thumbsController.photoSource = _photoSource;
[self.navigationController pushViewController:_thumbsController animated:YES];
}
}
}
首先是要下载three20并安装到工程里头。
如果是想手动将three20添加到xcode4.2的话,可参照此链接:添加three20到xcode4.2教程
如果想通过指令来将three20添加到xcode的话,可参照此链接通过指令将three20添加到xcode教程
通过指令来将three20添加到xcdoe时,操作比较快速。
但有几点需要注意。
1.尽量让下载的three20 与工程处于同一个目录,这样在后续的设置中会比较方便。
2.如果PROJECT的名称与TARGETS的名称不一样的话,那通过指令执行时,需要执行如下指令。
3.接着按这些步骤把相册添加到自己的工程中去,将图片相册添加到工程。
3,如何在现有的程序中单击某一按钮,然后导航到three20的相册中。代码如下:如果想进一步的了解导航具体情况,那么可以参照此链接。导航具体教程
- (IBAction)viewPhoto:(id)sender
{
NSLog(@"%@",currentImageName);
NSLog(@"%d",[currentImageName retainCount]);
[[TTURLRequestQueue mainQueue] setMaxContentLength:0];
TTNavigator *navigator = [TTNavigator navigator];
navigator.window = [UIApplication sharedApplication].keyWindow;
TTURLMap *map = navigator.URLMap;
[map from:@"tt://appPhotos" toSharedViewController:[PhotoViewController class]];
[navigator openURLAction:[TTURLAction actionWithURLPath:@"tt://appPhotos"]];
}
4,如果想从相册返回到原工程,可以在PhotoViewController.h 添加如下代码:
4.1添加返回按钮到导航栏
- (void) viewDidLoad {
UIBarButtonItem *listViewBackBtn = [[UIBarButtonItem alloc] initWithTitle:@"test"
style:UIBarButtonItemStylePlain
target:self
action:@selector(GoBack:)];
self.navigationItem.leftBarButtonItem = listViewBackBtn;
self.navigationItem.hidesBackButton = YES;
[listViewBackBtn release];
self.photoSource = [PhotoSet samplePhotoSet];
self.centerPhotoIndex = currentCaptureIndex; }
4.2添加返回按钮事件
//返回到视频观看页面
-(void) GoBack:(id)sender{
[[TTNavigator navigator] removeAllViewControllers];
}
5.如何在相册中添加删除事件。
5.1具体添加删除按钮以及事件可以参照此教程添加删除事件 、添加删除事件2
5.2 删除后的图片中兴的事件。如下:
//删除图片
- (void)deletePhotoAtIndex:(NSInteger)index
{
NSMutableArray *muPhotos = [PhotoSet samplePhotoSet].photos;
Photo *removePhoto = [muPhotos objectAtIndex:index];
NSString *removePhotoName = removePhoto.caption;
[self removePhotosOfDocuments:index removePhotoName:removePhotoName];
// [muPhotos removeObjectAtIndex:index];
self.photoSource = [PhotoSet samplePhotoSet];
self.centerPhotoIndex = index;
}
- (void) removePhotosOfDocuments:(NSInteger)index removePhotoName:(NSString *) removePhotoName
{
NSFileManager *fileManage = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask , YES) ;
NSString *documentDirectory = [paths objectAtIndex:0];
NSString *bigImagePath = [documentDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"BigImage/%@",removePhotoName]];
NSString *smallImagePath = [documentDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"SmallImage/small_%@",removePhotoName]];
NSError *error = nil;
[fileManage removeItemAtPath:bigImagePath error:&error];
[fileManage removeItemAtPath:smallImagePath error:&error];}
5.3如果上传某一张图片,然后返回照片缩略图查看器,结果发现照片缩略图查看器中被删除的图片还在,这时需要修改TTPhotoViewController这个类的方法:红色部分为新添加的。这样才能保持相册缩略图的同步。
TTPhotoViewController
- (void)showThumbnails {
NSString* URL = [self URLForThumbnails];
if (!_thumbsController) {
if (URL) {
// The photo source has a URL mapping in TTURLMap, so we use that to show the thumbs
NSDictionary* query = [NSDictionary dictionaryWithObject:self forKey:@"delegate"];
TTBaseNavigator* navigator = [TTBaseNavigator navigatorForView:self.view];
_thumbsController = [[navigator viewControllerForURL:URL query:query] retain];
[navigator.URLMap setObject:_thumbsController forURL:URL];
} else {
// The photo source had no URL mapping in TTURLMap, so we let the subclass show the thumbs
_thumbsController = [[self createThumbsViewController] retain];
_thumbsController.photoSource = _photoSource;
}
}
if (URL) {
TTOpenURLFromView(URL, self.view);
} else {
if ([self.navigationController isKindOfClass:[TTNavigationController class]]) {
_thumbsController.photoSource = _photoSource;
[(TTNavigationController*)self.navigationController
pushViewController: _thumbsController
animatedWithTransition: UIViewAnimationTransitionCurlDown];
} else {
_thumbsController.photoSource = _photoSource;
[self.navigationController pushViewController:_thumbsController animated:YES];
}
}
}
相关文章推荐
- iphone 如何将three20添加到xcode4.2中去
- 最大化/最小化/还原/关闭以及按钮图片的添加
- javafx TableValue 添加按钮列,以及删除列功能
- SVN的搭建及使用(三)用TortoiseSVN修改文件,添加文件,删除文件,以及如何解决冲突,重新设置用户名和密码等
- 添加删除、更新按钮的提示确认信息,以及DATAGRID的添加、插入、更新、删除操作。
- iOS如何添加图片资源以及设置应用程序图标
- Qt中为工程添加资源文件、给按钮添加图片
- 解决 ext中grid添加按钮列,如何进行动作响应,以及如何同步调用ext内部组件
- 如何解决Visual c++不能打开文件以及工程不能添加文件的问题
- 如何实现在TreeView中添加一个删除的按钮
- iphone simulator 如何添加图片到相册
- iOS如何添加图片资源以及设置应用程序图标
- 添加和删除索引以及如何给中间表添加两个主键
- 如果错误的删除了对话框的退出按钮,如何添加新的退出按钮?
- Qt中为工程添加资源文件、给按钮添加图片
- iphone 如何设置在uiImageView上添加按钮,按钮透明并且能响应事件
- 转:GridView 中如何给删除按钮添加提示
- 如何管理和记录 SSIS 各个 Task 的开始执行时间和结束时间以及 Task 中添加|删除|修改的记录数
- iphone 如何成功的把three20成功的添加到xcode中去。
- UCGUI中如何使用BUTTON_SetBMPEx()函数在按钮中添加图片问题