iOS 개발 사진 다중 선택 기능

2740 단어
오늘 야근을 해서 한가해서 사소한 걱정을 해결할 일이 없다. iOS 개발 사진에 다중 선택과 단일 선택이라는 기능을 추가하는 것은 너무 흔한 것 같고 아직 완전한 기능을 할 정력이 없다.잔말 말고 코드 올려.먼저 효과도를 보십시오:
addImage.gif
이 기능은 두 개의 타사 라이브러리를 사용했습니다.
https://github.com/iphone5solo/PYPhotoBrowser
https://github.com/banchichen/TZImagePickerController
PYPhotoBrowser 코코푸드를 사용하여 설치하는 방식: pod "PYPhotoBrowser" 그리고 메인 헤더 파일 가져오기#import TZImagePickerController 코코푸드를 사용하여 설치하는 방식: pod 'TZImagePickerController' 그리고 메인 헤더 파일 가져오기#import "TZImagePickerController.h만약에 이 두 제3자의 역할을 모르면git주소를 열어 문서에서 받아들인 에이전트를 TZImagePickerControllerDelegate,PYPhotosViewDelegate 속성을 정의하여 선택한 그림을 저장할 수 있습니다. 선택을 누르면 그림 단추 호출 방법을 추가합니다.
-(void)ininPhotoView{
    // 1.           photosView
    PYPhotosView *publishPhotosView = [PYPhotosView photosView];
    publishPhotosView.py_x = 5;
    publishPhotosView.py_y = 10;
    // 2.1       
    publishPhotosView.images = nil;
    // 3.     
    publishPhotosView.delegate = self;
    publishPhotosView.photosMaxCol = 4;//          
    publishPhotosView.imagesMaxCountWhenWillCompose = 3;//         
    // 4.   photosView
    [self.view addSubview:publishPhotosView];
    self.publishPhotosView = publishPhotosView;
}

완료해야 하는 에이전트 방법
#pragma mark - PYPhotosViewDelegate
- (void)photosView:(PYPhotosView *)photosView didAddImageClickedWithImages:(NSMutableArray *)images{
    //               ,     。
    [self getPhotos];
}

//미리 보기 그림에 들어갈 때 호출하면 미리 보기 컨트롤러를 얻을 수 있으며 내비게이션 표시줄에 대한 사용자 정의를 실현할 수 있습니다
- (void)photosView:(PYPhotosView *)photosView didPreviewImagesWithPreviewControlelr:(PYPhotosPreviewController *)previewControlelr{
    NSLog(@"      ");
}

앨범에 들어가는 방법:
-(void)getPhotos{
    CCDefineWeakSelf;
    TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:3-weakSelf.photos.count delegate:weakSelf];
    //      block    ,          .
    [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray *photos, NSArray *assets,BOOL isSelectOriginalPhoto){
        NSLog(@"photos===%@",photos);
        for (UIImage *image in photos) {
            [weakSelf requestData:image];//requestData:                
        }
        [weakSelf.photos addObjectsFromArray:photos];
    [self.publishPhotosView reloadDataWithImages:weakSelf.photos];
    }];
    [weakSelf presentViewController:imagePickerVc animated:YES completion:nil];
}
@property (nonatomic, weak) PYPhotosView *publishPhotosView;

좋은 웹페이지 즐겨찾기