您的位置:首页 > 其它

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];
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐