zoukankan      html  css  js  c++  java
  • UIScrollView创建相册

    1.设置滚动相册

    1.1将存放图片数组传过来,及当前图片的索引

    1.2在控制器中创建ScrollView,设置它的contentSize,contentOffset.

    1.3通过传过来的图片数组创建UIImageView并将每个UIImageView添加到ScrollView,ScrollView的ConSize是图片数组的总数乘以每个UIImageVIew的宽度.

    1.4滚动图片设置图片当前索引及总数.

    1.5删除图片操作

    1.51当删除图片的索引>0时,设置图片的偏移量是当前图片的索引-1*当前UIImageView的宽度,

    _imageScrollView.contentOffset = CGPointMake((self.currImageTag-1)*_imageScrollView.bounds.size.width, 0);

    1.52当删除图片的索引= 0时,设置图片的偏移是是当前图片的索引*当前UIImageView的宽度,

    _imageScrollView.contentOffset = CGPointMake((self.currImageTag)*_imageScrollView.bounds.size.width, 0);

    1.6当删除其中一个图片后,刷新视图重新设置当前的图片的索引及数组的总数,如果是列表形式的,按照九宫格方式重新布局.

    代码如下:

    CGRect frame = self.view.bounds;
        frame.origin.x -= gap;
        frame.size.width += (2* gap);
        _imageScrollView = [[UIScrollView alloc] initWithFrame:frame];
        _imageScrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        ;
        // 设置伸缩比例
        _imageScrollView.maximumZoomScale = 2.0;
        _imageScrollView.minimumZoomScale = 1.0;
        
        _imageScrollView.pagingEnabled = YES;
        _imageScrollView.delegate = self;
        _imageScrollView.showsHorizontalScrollIndicator = NO;
        _imageScrollView.showsVerticalScrollIndicator = NO;
        _imageScrollView.backgroundColor = [UIColor clearColor];
        
        if (self.imageArray && self.imageArray.count){
            _imageScrollView.contentSize = CGSizeMake(frame.size.width *self.imageArray.count, 0);
            
            for (NSInteger i = 0; i <self.imageArray.count; i++) {
                _imageView = [[UIImageView alloc] init];
                CGRect bounds = _imageScrollView.bounds;
                _imageView.frame = CGRectMake(i*bounds.size.width,0, bounds.size.width-gap, bounds.size.height);
                UIImage *image = self.imageArray[i];
                _imageView.userInteractionEnabled = YES;
                _imageView.tag = i+200;
                if (image && [image isKindOfClass:[UIImage class]]) {
                    _imageView.image = image;
                }
                [_imageScrollView addSubview:_imageView];
            }
        }
        
        [self.view addSubview:_imageScrollView];
        _imageScrollView.contentOffset = CGPointMake(self.currImageTag*frame.size.width, 0);
    将来的自己,会感谢现在不放弃的自己!
  • 相关阅读:
    如何入门深度学习?
    java opencv使用相关
    python操作Excel读写--使用xlrd
    从声学模型算法总结 2016 年语音识别的重大进步丨硬创公开课
    sift 与 surf 算法
    BP神经网络原理详解
    Nature重磅:Hinton、LeCun、Bengio三巨头权威科普深度学习
    浅谈流形学习(转)
    远离神经网络这个黑盒,人工智能不止这一条路可走
    对比深度学习十大框架:TensorFlow 并非最好?
  • 原文地址:https://www.cnblogs.com/TheYouth/p/5203537.html
Copyright © 2011-2022 走看看