1:ZIP文件压缩跟解压,使用ZipArchive

创建/添加一个zip包

ZipArchive* zipFile = [[ZipArchive alloc] init];

//次数得zipfilename需要一个完整得路径,例如***/Documents/demo.zip

[zipFile CreateZipFile2:@"zipfilename"]; 

//有两种可选得方式进行创建压缩包,带密码和不带密码的

[[zipFile CreateZipFile2:@"zipfilename" Password:@"your password"];

//接下来就是将需要压缩的文件添加到这个压缩包中

//这里第一个参数需要完整的路径,例如:***/Documents/a.txt  newname是指文件在压缩包中的名字,不需要路径,只是一个名称

[zipFile addFileToZip:@"fullpath of the file" newname:@"new name of the file without path"];

//如果需要将多个文件进行压缩,即压缩文件夹,重复addFileToZip方法即可

[zipFile CloseZipFile2];

解压zip包:

ZipArchive* zipFile = [[ZipArchive alloc] init];

[zipFile UnzipOpenFile:@"zip file name"]; 

//同样,对应的就有两种打开zip包的方式,带密码和不带密码

[zipFile UnzipOpenFile:@"zip file name" Password:@"password" ];

//压缩包释放到的位置,需要一个完整路径 

[zipFile UnzipFileTo:@"output path" overwrite:YES];

[zipFile UnzipCloseFile];

[zipFile release];

//记得释放
. 压缩:ZipArchive可以压缩多个文件,只需要把文件一一addFileToZip即可.

ZipArchive* zip = [[ZipArchive alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentpath = ([paths count] > ) ? [paths objectAtIndex:] : nil;
NSString* l_zipfile = [documentpath stringByAppendingString:@"/test.zip"] ; NSString* image1 = [documentpath stringByAppendingString:@"/image1.jpg"] ;
NSString* image2 = [documentpath stringByAppendingString:@"/image2.jpg"] ; BOOL ret = [zip CreateZipFile2:l_zipfile];
ret = [zip addFileToZip:image1 newname:@"image1.jpg"];
ret = [zip addFileToZip:image2 newname:@"image2.jpg"];
if( ![zip CloseZipFile2] )
{
l_zipfile = @"";
} . 解压缩: ZipArchive* zip = [[ZipArchive alloc] init];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentpath = ([paths count] > ) ? [paths objectAtIndex:] : nil; //路径地址要注意 NSString* l_zipfile = [documentpath stringByAppendingString:@"/test.zip"] ;
NSString* unzipto = [documentpath stringByAppendingString:@"/test"] ;
if( [zip UnzipOpenFile:l_zipfile] )
{
BOOL ret = [zip UnzipFileTo:unzipto overWrite:YES];
if( NO==ret )
{
}
[zip UnzipCloseFile];
}

2:UITapGestureRecognizer传值

UIImageView *imageView =[[UIImageView alloc]initWithFrame:CGRectMake(, , , )];

    imageView.image=[UIImageimageNamed:@"filter_laozhaopian_a.png"];

    imageView.tag = ;  //可以通过这样来给下边的点击事件传值

    imageView.userInteractionEnabled = YES;

    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizeralloc] initWithTarget:selfaction:@selector(UesrClicked:)];

    [imageView addGestureRecognizer:singleTap];

    [self.view addSubview:imageView];

- (void)UesrClicked:(UITapGestureRecognizer *)recognizer
{
NSLog(@"%d",(recognizer.view.tag - ));
}

 3:自定义self.navigationItem.titleView视图

UIView *titleView=[[UIView alloc] initWithFrame:CGRectMake(, , SCREEN_WIDTH, KTitleViewHeight)];

    //最新定义左边的按键
UIButton *leftItemButton=[UIButton buttonWithType:UIButtonTypeCustom];
leftItemButton.frame=CGRectMake(, , KLeftItemButtonWidth, KLeftItemButtonHeight);
[leftItemButton setBackgroundImage:[UIImage imageNamed:@"mapMarkNormal"] forState:UIControlStateNormal];
[leftItemButton setBackgroundImage:[UIImage imageNamed:@"mapMarkSelected"] forState:UIControlStateHighlighted];
[leftItemButton addTarget:self action:@selector(leftButtonAction) forControlEvents:UIControlEventTouchUpInside];
[titleView addSubview:leftItemButton];
[leftItemButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(titleView);
make.left.equalTo(titleView.mas_left).with.offset();
make.size.equalTo(CGSizeMake(KLeftItemButtonWidth, KLeftItemButtonHeight));
}]; UILabel *titleLabel=[UILabel new];
titleLabel.textAlignment=NSTextAlignmentCenter;
titleLabel.font=[UIFont systemFontOfSize:];
titleLabel.text=@"厦山中华公园广场";
[titleView addSubview:titleLabel];
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(titleView);
make.left.equalTo(titleView.mas_left).with.offset((SCREEN_WIDTH-KTitleViewTitleWidte-)/);
}]; UIButton *downButton=[UIButton new];
[downButton setImage:[UIImage imageNamed:@"FileDownload"] forState:UIControlStateNormal];
[titleView addSubview:downButton];
[downButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(titleView.mas_right).with.offset(-);
make.centerY.equalTo(titleView);
make.size.equalTo(CGSizeMake(KTitleViewButtonWidth, KTitleViewButtonHeight));
}]; UILabel *proLabel=[UILabel new];
proLabel.font=[UIFont systemFontOfSize:];
proLabel.textColor=[UIColor colorWithHexString:KWitTourism_AppTextColor];
proLabel.textAlignment=NSTextAlignmentRight;
proLabel.text=@"正在下载";
[titleView addSubview:proLabel]; [proLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(downButton.mas_left).with.offset(-);
make.centerY.equalTo(titleView);
make.size.equalTo(CGSizeMake(KTitleViewLabelWidth, KTitleViewLabelHeight));
}]; self.navigationItem.titleView=titleView;

4:实现无限滚动的uiscrollview

对滚动的图片数组头尾各增加一张,头则在其前面增加一张尾部的,尾部则插入一张第一张;并在滚动事件中进行处理,改变其位置;主体代码如下(若不自写也可以找相应插件,已封装):

/**
* @author wujunyang, 15-06-05 13:06:12
*
* @brief 头部滚动视图布局
*/
-(void)setupScrollView
{
int imgCount=self.imgdatalist.count; //如果没有值时 用一张默认的图片替换显示
if (imgCount==) {
UIImageView *featureImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"thirdEmpty"]];
featureImageView.frame=self.headerImageView.frame;
[self.headerImageView addSubview:featureImageView];
}
else{
//实际的图片个数
_actualImgNum=self.imgdatalist.count;
//为实现无限滚动 首先在第一个前面插入一个元素 此元素为最后一个
[self.imgdatalist insertObject:[self.imgdatalist objectAtIndex:([self.imgdatalist count]-)] atIndex:];
//在第后一个增加一个原先的第一个 由于上面已被插入一个值 所以原先的第一个变成第二个 所以此处为1
[self.imgdatalist addObject:[self.imgdatalist objectAtIndex:]];
//增加后的个数 用于处理定义滚动视图内容的总宽度
int imagDataListCount=self.imgdatalist.count; _scrollView=[[UIScrollView alloc]init];
_scrollView.frame=self.headerImageView.frame; for (int i=; i<self.imgdatalist.count; i++) {
AroundImgBean* aroundimgbean=[self.imgdatalist objectAtIndex:i];
// 获取图片
NSString *featureImageName = aroundimgbean.aroundimgurl;
UIImageView *featureImageView = [[UIImageView alloc] init];
[featureImageView sd_setImageWithURL:[NSURL URLWithString:featureImageName] placeholderImage:[UIImage imageNamed:@"thirdEmpty"]]; // 设置图片尺寸位置
CGFloat featureWidth = SCREEN_WIDTH;
CGFloat featureHeight = self.headerImageView.frame.size.height;
CGFloat featureX = SCREEN_WIDTH * i;
CGFloat featureY = ;
featureImageView.frame = CGRectMake(featureX, featureY, featureWidth, featureHeight);
[_scrollView addSubview:featureImageView];
} // 设置scrollView功能属性
_scrollView.userInteractionEnabled = YES;
_scrollView.bounces=NO;
_scrollView.scrollEnabled = YES; // 支持滚动
_scrollView.contentSize = CGSizeMake(self.headerImageView.frame.size.width * imagDataListCount, ); // 只需要水平滚动
_scrollView.pagingEnabled = YES; // 支持分页
_scrollView.showsHorizontalScrollIndicator = NO; // 隐藏水平滚动条 // 设置代理
_scrollView.delegate = self; // 添加
[self.headerImageView addSubview:_scrollView];
}
} //滚动事件
- (void)scrollViewDidScroll:(UIScrollView *)myscrollView {
if ([myscrollView isEqual:_scrollView]) {
// 四舍五入,让图片滚动超过中线的时候改变页码
if (self.imgdatalist.count>) {
CGFloat pageWidth = _scrollView.frame.size.width;
int page = floor((_scrollView.contentOffset.x - pageWidth / ) / pageWidth) + ;
_currentPageIndex=page; //当前页数要是没有超过实际的值时
if (_currentPageIndex<_actualImgNum) {
_imageCount=[NSString stringWithFormat:@"%d/%d",_currentPageIndex+,_actualImgNum];
}
else
{
_imageCount=[NSString stringWithFormat:@"%d/%d",,_actualImgNum];
} self.imageLabel.text=_imageCount;
}
else
{
_imageCountView.hidden=YES;
_imageLabel.hidden=YES;
}
}
} /**
* @author wujunyang, 15-06-05 11:06:06
*
* @brief 滚动事件处理 无限滚动 修改滚动的当前位置
* @param myscrollView <#myscrollView description#>
*/
- (void)scrollViewDidEndDecelerating:(UIScrollView *)myscrollView
{
if ([myscrollView isEqual:_scrollView]) {
if (_currentPageIndex==) { [_scrollView setContentOffset:CGPointMake(([self.imgdatalist count]-)*myscrollView.frame.size.width, )];
}
if (_currentPageIndex==([self.imgdatalist count]-)) { [_scrollView setContentOffset:CGPointMake(myscrollView.frame.size.width, )];
}
}
}

5:IOS开发实现歌词自动滚动功能一种实现方式

 _timer = [NSTimer scheduledTimerWithTimeInterval:0.09f target:self selector:@selector(rollLyc) userInfo:nil repeats:YES];

- (void)rollLyc
{
CGFloat currentTime = _audio.currentTime;
CGFloat lycTime = [_lycList[currentLine + ][@"time"] floatValue];//_lycList是存储有每句歌词和对应的时间的字典集合 currentLine设置为成员变量,在ViewDidLoad中初始为0 NSLog(@"%f --- %f ",currentTime,lycTime); if (currentTime >= lycTime) {
currentLine = currentLine + ;
}
NSIndexPath *indexpath = [NSIndexPath indexPathForRow:currentLine inSection:];
[self.tableView selectRowAtIndexPath:indexpath animated:YES scrollPosition:UITableViewScrollPositionMiddle];
}

6:iOS 从url中获取文件名以及后缀

//这里有一个模拟器沙盒路径(完整路径)

NSString* index=@"/Users/junzoo/Library/Application Support/iPhone Simulator/7.0.3/Applications/63925F20-AF97-4610-AF1C-B6B4157D1D92/Documents/DownLoad/books/2013_50.zip";

对路径截取的9种操作

    NSLog(@"1=%@",[index lastPathComponent]);

    NSLog(@"2=%@",[index stringByDeletingLastPathComponent]);

    NSLog(@"3=%@",[index pathExtension]);

    NSLog(@"4=%@",[index stringByDeletingPathExtension]);

    NSLog(@"5=%@",[index stringByAbbreviatingWithTildeInPath]);

    NSLog(@"6=%@",[index stringByExpandingTildeInPath]);

    NSLog(@"7=%@",[index stringByStandardizingPath]);

    NSLog(@"8=%@",[index stringByResolvingSymlinksInPath]);

    NSLog(@"9=%@",[[index lastPathComponent] stringByDeletingPathExtension]);

对应结果

 =2013_50.zip

 =/Users/junzoo/Library/Application Support/iPhone Simulator/7.0./Applications/63925F20-AF97--AF1C-B6B4157D1D92/Documents/DownLoad/books

=zip

 =/Users/junzoo/Library/Application Support/iPhone Simulator/7.0./Applications/63925F20-AF97--AF1C-B6B4157D1D92/Documents/DownLoad/books/2013_50

=~/Documents/DownLoad/books/2013_50.zip

 =/Users/junzoo/Library/Application Support/iPhone Simulator/7.0./Applications/63925F20-AF97--AF1C-B6B4157D1D92/Documents/DownLoad/books/2013_50.zip

 =/Users/junzoo/Library/Application Support/iPhone Simulator/7.0./Applications/63925F20-AF97--AF1C-B6B4157D1D92/Documents/DownLoad/books/2013_50.zip

=/Users/junzoo/Library/Application Support/iPhone Simulator/7.0./Applications/63925F20-AF97--AF1C-B6B4157D1D92/Documents/DownLoad/books/2013_50.zip

=2013_50

IOS开发基础知识--碎片14的更多相关文章

  1. IOS开发基础知识碎片-导航

    1:IOS开发基础知识--碎片1 a:NSString与NSInteger的互换 b:Objective-c中集合里面不能存放基础类型,比如int string float等,只能把它们转化成对象才可 ...

  2. IOS开发基础知识--碎片19

    1:键盘事件顺序 UIKeyboardWillShowNotification // 键盘显示之前 UIKeyboardDidShowNotification // 键盘显示完成后 UIKeyboar ...

  3. IOS开发基础知识--碎片33

    1:AFNetworking状态栏网络请求效果 直接在AppDelegate里面didFinishLaunchingWithOptions进行设置 [[AFNetworkActivityIndicat ...

  4. IOS开发基础知识--碎片42

    1:报thread 1:exc_bad_access(code=1,address=0x70********) 闪退 这种错误通常是内存管理的问题,一般是访问了已经释放的对象导致的,可以开启僵尸对象( ...

  5. IOS开发基础知识--碎片50

      1:Masonry 2个或2个以上的控件等间隔排序 /** * 多个控件固定间隔的等间隔排列,变化的是控件的长度或者宽度值 * * @param axisType 轴线方向 * @param fi ...

  6. IOS开发基础知识--碎片3

    十二:判断设备 //设备名称 return [UIDevice currentDevice].name; //设备型号,只可得到是何设备,无法得到是第几代设备 return [UIDevice cur ...

  7. IOS开发基础知识--碎片11

    1:AFNetwork判断网络状态 #import “AFNetworkActivityIndicatorManager.h" - (BOOL)application:(UIApplicat ...

  8. IOS开发基础知识--碎片16

    1:Objective-C语法之动态类型(isKindOfClass, isMemberOfClass,id) 对象在运行时获取其类型的能力称为内省.内省可以有多种方法实现. 判断对象类型 -(BOO ...

  9. IOS开发基础知识--碎片40

    1:Masonry快速查看报错小技巧 self.statusLabel = [UILabel new]; [self.contentView addSubview:self.statusLabel]; ...

随机推荐

  1. 前端学PHP之面向对象系列第三篇——三大特性

    × 目录 [1]封装 [2]继承[3]多态 前面的话 php面向对象编程的三大特性是封装性.继承性和多态性.本文将介绍php的这三大特性 封装 封装就是把对象中的成员属性和成员方法加上访问修饰符( p ...

  2. Android之JSON解析

    做个Android网络编程的同学一定对于JSON解析一点都不陌生,因为现在我们通过手机向服务器请求资源,服务器给我们返回的数据资源一般都是以JSON格式返回,当然还有一些通过XML格式返回,相对JSO ...

  3. Android NDK开发初识

    神秘的Android NDK开发往往众多程序员感到兴奋,但又不知它为何物,由于近期开发应用时,为了是开发的.apk文件不被他人解读(反编译),查阅了很多资料,其中有提到使用NDK开发,怀着好奇的心理, ...

  4. (转)使用minicpan创建本地CPAN

    在临时的办公场所网络不畅,有时不能下载cpan上的软件包,所有只能自建一个cpan. 这里使用了工具'minicpan',简单地说:就是把互联网上的CPAN搬到自己的电脑里,它的最初想法来自Randa ...

  5. 在非SQL客户端使用命令行方式定期连接SQL Server 服务器并模拟用户查询操作,同时输出信息内容

    一个很长的标题,实现的功能就是尽量使用非人力的方式模拟人去做一件事情,为了便于记录,将他们输出成文件方便查阅. 图形界面方式,使用微软自己的ConnMaker.exe,或者Microsoft 数据连接 ...

  6. dapper-dot-net用法及其扩展系列

    dapper-dot-net用法及其扩展系列 虽然已经一段时间没写.net了,但是昨天看了下dapper和Dapper-Extensions在github仍然有更新,他们的受欢迎程度可想而知.所以想把 ...

  7. [Data Structure & Algorithm] Hash那点事儿

    哈希表(Hash Table)是一种特殊的数据结构,它最大的特点就是可以快速实现查找.插入和删除.因为它独有的特点,Hash表经常被用来解决大数据问题,也因此被广大的程序员所青睐.为了能够更加灵活地使 ...

  8. JQuery中使用Ajax实现诸如登录名检测等异步请求Demo

    上一篇博客介绍了注册登录时一次性图形验证码的工具类的编写,这篇随笔同样是我在写用jquery中ajax实现登录信息检测的异步请求功能的笔记,在各个网站进行信息用户注册时,需要在不刷新页面的情况下对注册 ...

  9. 关于replace()方法中第二个参数的转义问题

    如果你想通过Javascript代码在网页中呈现 \ 字符,则在JS代码中你必须输入两个反斜杠 \\,否则会报错.比如: var a = "\"; alert(a); //chro ...

  10. C#字符串的不变性

    看过一些C#教程的人都应该知道这句话:“在C#中,一旦对字符串对象进行初始化,该字符串对象就不能再被该变“.这句话可用简单的图示来说明: 1.声明变量 string str="first&q ...