技术文章分类(180)

技术随笔(11)

UICollectionView实现的图片的多选效果(本人已封装好,简单操作)

github 下载demo:https://github.com/MartinLi841538513/MartinDemos (一切以demo为准)

先说操作,有时间再说我的设计原理。

 

两种模式:

模式一:getImageMode,可从相册或拍照获取图片,并可全屏浏览已选图片。

模式二:BrowseImageMode,可查看网络图片,本地图片,可全屏浏览这些图片。

 

我的操作是基于ELCImagePickerController,AFNetWorking第三方的,以及自己之前封装的MartinLiPageScrollView,所以先导入

pod 'ELCImagePickerController', '~> 0.2.0'

pod 'AFNetworking', '~> 2.5.0'

再从,从MartinDemos中导入ELCImagePickerHelp文件夹和MartinLiPageScrollView文件夹,这个文件夹里面是我封装的。

详细步骤如下:

现在的使用就很简单了(这里我只用了模式一)

.h

#import <UIKit/UIKit.h>
@interface MLMutiImagesChooseViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIView *collectionview;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *collectionviewHeight;
@end

.m 这里注意MLMutiImagesChoosenViewController最好是要设置成全局的,因为你肯定是需要在后面某地地方获取到collectionview得images的。

#import "MLMutiImagesChooseViewController.h"
#import "MLMutiImagesChoosenViewController.h"
@interface MLMutiImagesChooseViewController ()
{
    MLMutiImagesChoosenViewController *mutiImagesContoller;
}
@end

@implementation MLMutiImagesChooseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MLMutiImagesViewController" bundle:nil];//(必选)
    mutiImagesContoller = [storyboard instantiateViewControllerWithIdentifier:@"MLMutiImagesChoosenViewController"];//(必选)
    mutiImagesContoller.fatherController = self;//(必选)
    mutiImagesContoller.imageMode = getImagesMode;//(必选)
    mutiImagesContoller.superView = self.collectionview;//(必选)
    mutiImagesContoller.collectionviewHeight = self.collectionviewHeight.constant;//(必选)
    [self addChildViewController:mutiImagesContoller];//(必选)
    [self.collectionview addSubview: mutiImagesContoller.collectionView];//(必选)
}

- (IBAction)showCountAction:(id)sender {
    self.showCountLabel.text = [NSString stringWithFormat:@"%d",mutiImagesContoller.chooseImages.count];
}
@end

 

 

 

posted @ 2014-12-20 15:51  坤哥MartinLi  阅读(2756)  评论(1编辑  收藏  举报