博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iphone Three20如何添加到工程,以及如何添加删除图片的按钮。
阅读量:7226 次
发布时间:2019-06-29

本文共 4025 字,大约阅读时间需要 13 分钟。

     最近由于项目需要,需要做一个相册查看器来查看项目截图的图片。于是发现Three20的功能很强大,有自带的相册功能,于是就将其引用到工程里头来。

 首先是要下载three20并安装到工程里头。

   如果是想手动将three20添加到xcode4.2的话,可参照此链接:

   如果想通过指令来将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具体添加删除按钮以及事件可以参照此教程 、

        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];
    }
  }
}

 

           

       

 

    

 

转载于:https://www.cnblogs.com/85538649/archive/2011/12/23/2298917.html

你可能感兴趣的文章
位状态的使用
查看>>
面试技术题笔记
查看>>
Myth源码解析系列之一-项目简介
查看>>
JS易混淆的方法整理
查看>>
iOS下JS与OC互相调用(八)--Cordova详解+实战
查看>>
七牛实时音视频云视频连线demo(web部分)
查看>>
Netty源码分析(六):SelectedSelectionKeySetSelector
查看>>
forEach,for...of,map与asycn/await
查看>>
springboot 2 Hikari 多数据源配置问题(dataSourceClassName or jdbcUrl is required)
查看>>
Golang数据库编程之GORM模型定义与数据库迁移
查看>>
Oracle redo解析之-4、rowid的计算
查看>>
Easy Scheduler 1.0.3 发布,分布式工作流任务调度系统
查看>>
java 颠倒整数
查看>>
Python入门教程100天:Day05-练习总结
查看>>
环境搭建,8种基本类型,Static,package和import,log4j
查看>>
即将到来的 Debian 10 Buster 发布版的新特点
查看>>
iOS 头部视图下拉变大
查看>>
Disruptor并发框架
查看>>
react-hooks 实现简单的评论list
查看>>
【多图警告】学会JavaScript测试你就是同行中最亮的仔(妹)
查看>>