图片的浏览,删除

1.h 文件

#import <UIKit/UIKit.h>

#import "BaseViewController.h"


/**

 * 图片查看视图

 **/


typedef void (^EditPhotosCompleteBlock)(NSInteger index);


@interface EditPhotosController : BaseViewController

@property (retain, nonatomic) NSMutableArray *imageArray;       //展示图片数组

@property (assign, nonatomic) NSInteger selectIndex;                  //选中的下标

@property (copy, nonatomic) EditPhotosCompleteBlock editPhotosComplete;

@end



2.m文件

#import "EditPhotosController.h"

#import "ShowJoyAlterView.h"


@interface EditPhotosController ()<UIScrollViewDelegate>


@property (strong ,nonatomic) UIScrollView    *imageScrollView;

@property (strong ,nonatomic) UILabel         *mLabTitle;


@end


@implementation EditPhotosController

@synthesize imageArray;

@synthesize selectIndex;


- (void)viewDidLoad

{

    [super viewDidLoad];

    self.view.backgroundColor = UIColorFromRGB(0X1B1A1F);

    [self addviewNavagationBar];

    

}


- (void)viewDidAppear:(BOOL)animated

{

    [self initScrollView];

    [self updateDatas:imageArray];


}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

}



#pragma mark - Init

// 初始化navagationBar

-(void)addviewNavagationBar{

    UIImageView * mviewNavigationBar = [self addNavagationBar];

    [self.view addSubview:mviewNavigationBar];

    

    // 删除

    UIImageView *mImgView = [self addImageView:CGRectMake(Screen_width - 35 , IOS7_OR_LATER?25:(44-21)/2, 20 , 21) withImageStr:@"NavigationBarDelete"];

    mImgView.userInteractionEnabled = YES;

    [mviewNavigationBar addSubview:mImgView];

    

    UITapGestureRecognizer *mImageViewTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(mImageViewBroswerDelete)];

    [mImgView addGestureRecognizer:mImageViewTap];

    

    // title

    self.mLabTitle = [self addLableText:CGRectMake(50, IOS7_OR_LATER?29:(44-21)/2, Screen_width-100, 18 * BEI6) withLabText:@"" withLabFont:[UIFont fontWithName:HeitiSCLight size:17.5 * BEI6] withTextColor:[UIColor whiteColor]];

    self.mLabTitle.textAlignment=NSTextAlignmentCenter;

    [mviewNavigationBar addSubview:self.mLabTitle];

    

    // 返回

    UIButton* mBtnLeftItem = [self.view addButtton:CGRectMake(0, IOS7_OR_LATER?29:(44-21)/2, 46, 20) title:nil target:self action:@selector(backClick) tag:001 withFont:nil];

    [mBtnLeftItem setImage:[UIImage imageNamed:@"DRPersonNext"] forState:UIControlStateNormal];

    mBtnLeftItem.imageEdgeInsets = UIEdgeInsetsMake(0, 11, 0, 21);

    [mviewNavigationBar addSubview:mBtnLeftItem];

}


-(UIImageView *)addNavagationBar{

    

    UIImageView * mImageviewNavigationBar = [[UIImageView alloc] init];

    mImageviewNavigationBar.frame=CGRectMake(0, 0, Screen_width, IOS7_OR_LATER?64:44);

    mImageviewNavigationBar.userInteractionEnabled=YES;

    mImageviewNavigationBar.backgroundColor = Distribute1;

    return mImageviewNavigationBar;

}


- (void)backClick

{

    [self.navigationController popViewControllerAnimated:YES];

    

}


- (void)initScrollView

{

    self.imageScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0 , 64, Screen_width, Screen_height)];

    self.imageScrollView.pagingEnabled = YES;

    self.imageScrollView.delegate = self;

    [self.view addSubview:self.imageScrollView];

    

    self.imageScrollView.contentOffset = CGPointMake(self.view.frame.size.width * self.selectIndex, 0);

}


#pragma mark - EditPhotos


- (void)updateDatas:(NSMutableArray *)tempImageArray

{

     self.mLabTitle.text = [NSString stringWithFormat:@"%ld/%lu",self.selectIndex+1,(unsigned long)[self.imageArray count]];

    

    [self removeAllSubViewsOfView:self.imageScrollView];

    

    int height = 480;

    if (self.view.frame.size.height == 568) {

        height = 568;

    }

    

    self.imageScrollView.contentSize = CGSizeMake(self.view.frame.size.width*[tempImageArray count],height-64);

    

    

    UIImageView *photoView;

    for (int i = 0; i < [tempImageArray count] ; i++ ) {

        photoView = [[UIImageView alloc]initWithFrame:CGRectMake(self.view.frame.size.width * i, 42 * BEI6, self.view.frame.size.width, height)];

        [photoView setImage:[tempImageArray objectAtIndex:i]];

        photoView.contentMode = UIViewContentModeScaleAspectFit;

        [self.imageScrollView addSubview:photoView];

    }

}


#pragma mark - NavigationBarButtonAction

//删除

- (void)mImageViewBroswerDelete

{

    

    if (self.imageArray.count == 1) {

        [self.view showSGInfoAlert:@"不能再删除了哦~"];

    }else{

        

        ShowJoyAlterView * alterView = [[ShowJoyAlterView alloc] initWithTitle:@"提示" withDetailFirst:@"是否删除该照片?" withDetailSecond:@"" withLeftButtonTitle:@"取消" withRightButtonTitle:@"确定"];

        alterView.rightBlock = ^(){

            [self.imageArray removeObjectAtIndex:self.selectIndex];

            self.editPhotosComplete(self.selectIndex);

            if (self.selectIndex != 0) {

                self.selectIndex --;

            }

            [self updateDatas:self.imageArray];

        };

        [alterView show];

    }

    

}


#pragma makr - ScrollViewDelegate


- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

    selectIndex = self.imageScrollView.contentOffset.x/self.view.frame.size.width;

    self.mLabTitle.text = [NSString stringWithFormat:@"%ld/%lu",self.selectIndex+1,(unsigned long)[self.imageArray count]];

}


#pragma mark - Util

- (void)removeAllSubViewsOfView:(UIView *)superView

{

    for (UIView *tempView in [superView subviews]) {

        [tempView removeFromSuperview];

    }

}



@end



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值