Basic knowledge of IOS development-fragment 14, basic knowledge of ios-Fragment

Source: Internet
Author: User
Tags ziparchive

Basic knowledge of IOS development-fragment 14, basic knowledge of ios-Fragment

1. ZIP files are compressed and decompressed using ZipArchive

Create/Add a zip package ZipArchive * zipFile = [[ZipArchive alloc] init]; // The zipfilename must have a complete path, for example, ***/Documents/demo.zip [zipFile CreateZipFile2: @ "zipfilename"]; // you can create a compressed package in either of the following ways, [[zipFile CreateZipFile2: @ "zipfilename" Password: @ "your password"] with or without a Password; // Add the file to be compressed to this package // The first parameter needs the complete path, for example: * **/Documents/a.txt newname refers to the name of the file in the compressed package, which does not need a path. It is just a name [zipFile addFileToZip: @ "fullpath of the file" newname: @ "new name of the file without path"]; // If You Need To Compress multiple files, that is, compress the folder. Repeat addFileToZip to [zipFile CloseZipFile2]. decompress the zip package: zipArchive * zipFile = [[ZipArchive alloc] init]; [zipFile UnzipOpenFile: @ "zip file name"]; // similarly, there are two methods to open a zip package, [zipFile UnzipOpenFile: @ "zip file name" Password: @ "password"]; // when the compressed package is released, a full path [zipFile UnzipFileTo: @ "output path" overwrite: YES]; [zipFile UnzipCloseFile]; [zipFile release]; // remember to release

 

1. compression: ZipArchive can compress multiple files. You only need to addFileToZip the files one by one. 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.j Pg "]; if (! [Zip CloseZipFile2]) {l_zipfile = @ "" ;}2. decompress: ZipArchive * zip = [[ZipArchive alloc] init]; NSArray * paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES); NSString * documentpath = ([paths count]> 0 )? [Paths objectAtIndex: 0]: nil; // The path address. Note 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; // You can pass the imageView value to the Click Event below. userInteractionEnabled = YES; optional * singleTap = [[Response] initWithTarget: selfaction: @ selector (UesrClicked :)]; [imageView addGestureRecognizer: singleTap]; [self. view addSubview: imageView];-(void) UesrClicked :( UITapGestureRecognizer *) recognizer {NSLog (@ "% d", (recognizer. view. tag-1000 ));}

3: Custom self. navigationItem. titleView View

UIView * titleView = [[UIView alloc] initWithFrame: CGRectMake (0, 0, SCREEN_WIDTH, KTitleViewHeight)]; // the button on the left of the latest definition UIButton * handle = [UIButton buttonWithType: UIButtonTypeCustom]; leftItemButton. frame = CGRectMake (0, 0, success, success); [Response setBackgroundImage: [UIImage imageNamed: @ "mapMarkNormal"] forState: UIControlStateNormal]; [Response setBackgroundImage: [UIImage imageNamed: @ "mapMarkSelected"] forState: Success]; [modify addTarget: self action: @ selector (leftButtonAction) forControlEvents: Success]; [titleView addSubview: leftItemButton]; [Export mas_makeConstraints: ^ (MASConstraintMaker * make) {make. centerY. similar to (titleView); make. left. failed to (titleView. mas_left ). with. offset (5); make. size. similar to (CGSizeMake (KLeftItemButtonWidth, KLeftItemButtonHeight);}]; UILabel * titleLabel = [UILabel new]; titleLabel. textAlignment = NSTextAlignmentCenter; titleLabel. font = [UIFont systemFontOfSize: 14]; titleLabel. text = @ "xiashan Zhonghua Park Plaza"; [titleView addSubview: titleLabel]; [titleLabel mas_makeConstraints: ^ (MASConstraintMaker * make) {make. centerY. similar to (titleView); make. left. failed to (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. failed to (titleView. mas_right ). with. offset (-2); make. centerY. similar to (titleView); make. size. failed to (CGSizeMake (KTitleViewButtonWidth, KTitleViewButtonHeight);}]; UILabel * proLabel = [UILabel new]; proLabel. font = [UIFont systemFontOfSize: 10]; proLabel. textColor = [UIColor colorWithHexString: KWitTourism_AppTextColor]; proLabel. textAlignment = NSTextAlignmentRight; proLabel. text = @ "downloading"; [titleView addSubview: proLabel]; [proLabel mas_makeConstraints: ^ (MASConstraintMaker * make) {make. right. failed to (downButton. mas_left ). with. offset (-5); make. centerY. similar to (titleView); make. size. similar to (CGSizeMake (KTitleViewLabelWidth, KTitleViewLabelHeight);}]; self. navigationItem. titleView = titleView;

4: Implement unlimited scrolling uiscrollview

Add one to the beginning and end of the Scrolling Image array, add one to the front of the array, and insert the first one to the end. Process and change the position of the array in the rolling event; the main code is as follows (you can find the corresponding plug-in without self-writing, encapsulated):/*** @ author wujunyang, 15-06-05 13:06:12 ** @ brief head scroll view Layout */-(void) setupScrollView {int imgCount = self. imgdatalist. count; // if there is no value, use a default image to replace the display if (imgCount = 0) {UIImageView * featureImageView = [[UIImageView alloc] initWithImage: [UIImage imageNamed: @ "thirdEmpty"]; featureImageView. frame = self. headerImageView. frame; [self. headerImageView addSubview: featureImageView];} else {// actual number of images _ actualImgNum = self. imgdatalist. count; // to implement infinite scrolling, insert an element before the first one. This element is the last [self. imgdatalist insertObject: [self. imgdatalist objectAtIndex :( [self. imgdatalist count]-1)] atIndex: 0]; // Add the first entry to the first entry. Because a value has been inserted above, the first entry is changed to the second entry. Therefore, the value is 1 [self. imgdatalist addObject: [self. imgdatalist objectAtIndex: 1]; // The added number is used to process the total width 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]; // obtain the image NSString * featureImageName = aroundimgbean. break; UIImageView * featureImageView = [[UIImageView alloc] init]; [featureImageView failed: [NSURL URLWithString: featureImageName] placeholderImage: [UIImage imageNamed: @ "success"]; // set the image size position 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];} // sets the scrollView function attribute _ scrollView. userInteractionEnabled = YES; _ scrollView. bounces = NO; _ scrollView. scrollEnabled = YES; // supports rolling _ scrollView. contentSize = CGSizeMake (self. headerImageView. frame. size. width * imagDataListCount, 0); // you only need to scroll horizontally _ scrollView. pagingEnabled = YES; // page_scrollview is supported. showsHorizontalScrollIndicator = NO; // hide the horizontal scroll bar // set proxy _ scrollView. delegate = self; // Add [self. headerImageView addSubview: _ scrollView] ;}// rolling event-(void) rollback :( UIScrollView *) myscrollView {if ([myscrollView isEqual: _ scrollView]) {// rounding, change the page number if (self. imgdatalist. count> 0) {CGFloat pageWidth = _ scrollView. frame. size. width; int page = floor (_ scrollView. contentOffset. x-pageWidth/2)/pageWidth) + 1; _ currentPageIndex = page; // if the current page number does not exceed the actual value, 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 rolling event processing infinite scrolling modify the current rolling position * @ param myscrollView <# myscrollView description #> */-(void) failed :( 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)] ;}}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.