麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 學院 > 開發設計 > 正文

IOS開發基礎知識--碎片14

2019-11-14 18:52:43
字體:
來源:轉載
供稿:網友

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];//記得釋放

 

1. 壓縮:ZipArchive可以壓縮多個文件,只需要把文件一一addFileToZip即可.ZipArchive* zip = [[ZipArchive alloc] init];NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);NSString *documentpath = ([paths count] > 0) ? [paths objectAtIndex:0] : 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 = @"";  } 2. 解壓縮:ZipArchive* zip = [[ZipArchive alloc] init];NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);NSString *documentpath = ([paths count] > 0) ? [paths objectAtIndex:0] : 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(100, 100, 200, 200)];    imageView.image=[UIImageimageNamed:@"filter_laozhaopian_a.png"];    imageView.tag = 10000;  //可以通過這樣來給下邊的點擊事件傳值    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 - 1000));} 

 3:自定義self.navigationItem.titleView視圖

UIView *titleView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, KTitleViewHeight)];        //最新定義左邊的按鍵    UIButton *leftItemButton=[UIButton buttonWithType:UIButtonTypeCustom];    leftItemButton.frame=CGRectMake(0, 0, 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(5);        make.size.equalTo(CGSizeMake(KLeftItemButtonWidth, KLeftItemButtonHeight));    }];        UILabel *titleLabel=[UILabel new];    titleLabel.textAlignment=NSTextAlignmentCenter;    titleLabel.font=[UIFont systemFontOfSize:14];    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-10)/2);    }];        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(-2);        make.centerY.equalTo(titleView);        make.size.equalTo(CGSizeMake(KTitleViewButtonWidth, KTitleViewButtonHeight));    }];        UILabel *PRoLabel=[UILabel new];    proLabel.font=[UIFont systemFontOfSize:10];    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(-5);        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==0) {        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]-1)] atIndex:0];        //在第后一個增加一個原先的第一個 由于上面已被插入一個值 所以原先的第一個變成第二個 所以此處為1        [self.imgdatalist addObject:[self.imgdatalist objectAtIndex:1]];        //增加后的個數 用于處理定義滾動視圖內容的總寬度        int imagDataListCount=self.imgdatalist.count;        _scrollView=[[UIScrollView alloc]init];        _scrollView.frame=self.headerImageView.frame;                for (int i=0; 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 = 0;            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, 0); // 只需要水平滾動        _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>0) {        CGFloat pageWidth = _scrollView.frame.size.width;        int page = floor((_scrollView.contentOffset.x - pageWidth / 2) / pageWidth) + 1;        _currentPageIndex=page;        //當前頁數要是沒有超過實際的值時        if (_currentPageIndex<_actualImgNum) {            _imageCount=[NSString stringWithFormat:@"%d/%d",_currentPageIndex+1,_actualImgNum];        }        else        {            _imageCount=[NSString stringWithFormat:@"%d/%d",1,_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==0) {                        [_scrollView setContentOffset:CGPointMake(([self.imgdatalist count]-2)*myscrollView.frame.size.width, 0)];        }        if (_currentPageIndex==([self.imgdatalist count]-1)) {                        [_scrollView setContentOffset:CGPointMake(myscrollView.frame.size.width, 0)];        }    }}

 


上一篇:ios開發學習筆記(1)

下一篇:Objective-C

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 日韩精品中文字幕在线观看 | 亚洲精品成人18久久久久 | 欧美aaaaa一级毛片在线 | 中文字幕伦乱 | 98国内自拍在线视频 | 天天色宗合 | 777sesese| 久久久日韩精品一区二区 | 欧美不卡 | 韩毛片| av91肉丝一区二区电影 | 色猫av| 亚洲啊v在线观看 | 黄污视频在线看 | 在线视频观看一区二区 | 久久国产成人精品国产成人亚洲 | 国产精品成人一区二区三区电影毛片 | 亚洲精品久久久久www | 国产无遮挡一级毛片 | 国产最新网站 | 污视频在线免费 | 成年人视频在线免费观看 | www.99热精品| 欧洲狠狠鲁 | 久久精品99久久久久久2456 | 亚洲免费视频大全 | 毛片免费视频播放 | 久久久久久久久浪潮精品 | 极品销魂一区二区三区 | 一级黄色性感片 | 黄色片在线免费播放 | 成人短视频在线观看 | 粉嫩粉嫩一区二区三区在线播放 | 毛片视频网址 | 欧美精品久久久久久久多人混战 | 国产在线精品一区二区不卡 | 欧美精品成人一区二区在线观看 | 久久精品亚洲欧美日韩精品中文字幕 | 国产在线观看免费视频软件 | 最新av在线免费观看 | 成人在线视频国产 |