zoukankan      html  css  js  c++  java
  • QBImagePickerController 用法

    //
    //  ViewController.m
    //  QBImagePickerControllerDemo
    //
    //  Created by Tanaka Katsuma on 2013/12/30.
    //  Copyright (c) 2013年 Katsuma Tanaka. All rights reserved.
    //
    
    #import "ViewController.h"
    #import <AssetsLibrary/AssetsLibrary.h>
    
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        if (![QBImagePickerController isAccessible]) {
            NSLog(@"Error: Source is not accessible.");
        }
    }
    
    
    #pragma mark - UITableViewDelegate
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        QBImagePickerController *imagePickerController = [[QBImagePickerController alloc] init];
        imagePickerController.delegate = self;
        imagePickerController.allowsMultipleSelection = (indexPath.section == 1);
        
        if (indexPath.section == 1) {
            switch (indexPath.row) {
                case 1:
                    imagePickerController.minimumNumberOfSelection = 3;
                    break;
                    
                case 2:
                    imagePickerController.maximumNumberOfSelection = 6;
                    break;
                    
                case 3:
                    imagePickerController.minimumNumberOfSelection = 3;
                    imagePickerController.maximumNumberOfSelection = 6;
                    break;
                    
                default:
                    break;
            }
        }
        
        if (indexPath.section == 0 && indexPath.row == 1) {
            [self.navigationController pushViewController:imagePickerController animated:YES];
        } else {
            UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:imagePickerController];
            [self presentViewController:navigationController animated:YES completion:NULL];
        }
    }
    
    - (void)dismissImagePickerController
    {
        if (self.presentedViewController) {
            [self dismissViewControllerAnimated:YES completion:NULL];
        } else {
            [self.navigationController popToViewController:self animated:YES];
        }
    }
    
    
    #pragma mark - QBImagePickerControllerDelegate
    
    - (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didSelectAsset:(ALAsset *)asset
    {
        NSLog(@"*** qb_imagePickerController:didSelectAsset:");
        NSLog(@"%@", asset);
        [self dismissImagePickerController];
    }
    
    - (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didSelectAssets:(NSArray *)assets
    {
        NSLog(@"*** qb_imagePickerController:didSelectAssets:");
        NSLog(@"%@", assets);
        
        [self dismissImagePickerController];
    }
    
    - (void)qb_imagePickerControllerDidCancel:(QBImagePickerController *)imagePickerController
    {
        NSLog(@"*** qb_imagePickerControllerDidCancel:");
        
        [self dismissImagePickerController];
    }
    
    @end

    启动测试程序 会有一个闪退 需要修改 QBAssetsCollectionViewController.m

    - (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
    {
        if (kind == UICollectionElementKindSectionFooter) {
            QBAssetsCollectionFooterView *footerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter
                                                                                          withReuseIdentifier:@"FooterView"
                                                                                                 forIndexPath:indexPath];
            
            switch (self.filterType) {
                case QBImagePickerControllerFilterTypeNone:{
                    NSString *format;
                    if (self.numberOfPhotos == 1) {
                        if (self.numberOfVideos == 1) {
                            format = @"format_photo_and_video";
                        } else {
                            format = @"format_photo_and_videos";
                        }
                    } else if (self.numberOfVideos == 1) {
                        format = @"format_photos_and_video";
                    } else {
                        format = @"format_photos_and_videos";
                    }
                    NSLog(@"%@",NSLocalizedStringFromTableInBundle(format,
                                                                   @"QBImagePickerController",
                                                                   [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"QBImagePickerController" ofType:@"bundle"]],
                                                                   nil));
                    
                    footerView.textLabel.text = [NSString stringWithFormat:@"%ld Photo, %ld Video",
                                                 (unsigned long)self.numberOfPhotos,
                                                 (unsigned long)self.numberOfVideos
                                                 ];
                    break;
                }
    
                case QBImagePickerControllerFilterTypePhotos:{
    //                NSString *format = (self.numberOfPhotos == 1) ? @"format_photo" : @"format_photos";
    //                footerView.textLabel.text = [NSString stringWithFormat:NSLocalizedStringFromTableInBundle(format,
    //                                                                                                          @"QBImagePickerController",
    //                                                                                                          [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"QBImagePickerController" ofType:@"bundle"]],
    //                                                                                                          nil),
    //                                                                                                  self.numberOfPhotos
    //                                                                                                  ];
                    footerView.textLabel.text = [NSString stringWithFormat:@"%ld Photo, %ld Video",
                                                 (unsigned long)self.numberOfPhotos,
                                                 (unsigned long)self.numberOfVideos
                                                 ];
                    break;
                }
                    
                case QBImagePickerControllerFilterTypeVideos:{
    //                NSString *format = (self.numberOfVideos == 1) ? @"format_video" : @"format_videos";
    //                footerView.textLabel.text = [NSString stringWithFormat:NSLocalizedStringFromTableInBundle(format,
    //                                                                                                          @"QBImagePickerController",
    //                                                                                                          [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"QBImagePickerController" ofType:@"bundle"]],
    //                                                                                                          nil),
    //                                                                                                  self.numberOfVideos
    //                                                                                                  ];
    
                    footerView.textLabel.text = [NSString stringWithFormat:@"%ld Photo, %ld Video",
                                                 (unsigned long)self.numberOfPhotos,
                                                 (unsigned long)self.numberOfVideos
                                                 ];
                    break;
                }
            }
            
            return footerView;
        }
        
        return nil;
    }

    https://github.com/questbeat/QBImagePicker 

  • 相关阅读:
    UOJ179
    Codeforces603E
    洛谷P4219
    Vijos1655
    JS对象 四舍五入round() round() 方法可把一个数字四舍五入为最接近的整数。 语法: Math.round(x)
    JS对象 向下取整floor() floor() 方法可对一个数进行向下取整。 语法: Math.floor(x)
    JS对象 向上取整ceil() ceil() 方法可对一个数进行向上取整。 语法: Math.ceil(x) 注意:它返回的是大于或等于x,并且与x最接近的整数。
    JS对象 神奇的Math对象,提供对数据的数学计算。注意:Math 对象是一个固有的对象,无需创建它,直接把 Math 作为对象使用就可以调用其所有属性和方法。这是它与Date,String对象的区别
    JS对象 提取指定数目的字符substr() substr() 方法从字符串中提取从 startPos位置开始的指定数目的字符串。
    JS对象 substring() 方法用于提取字符串中介于两个指定下标之间的字符。
  • 原文地址:https://www.cnblogs.com/nonato/p/4402652.html
Copyright © 2011-2022 走看看