ios图片放大

来源:互联网 发布:网络查水表是什么意思 编辑:程序博客网 时间:2024/05/16 11:39

//
//  BedroomInspectionViewController.m
//  ToiletinspectionReport
//
//  Created by admin on 13-9-3.
//  Copyright (c) 2013年 admin. All rights reserved.
//

#import "DetailViewController.h"
#import "DetailTableViewCell.h"
#import "AppDelegate.h"
#import "PicProcess.h"
#import "NSArray+ObjectAtIndexStrict.h"
#define BIG_IMG_WIDTH  300.0
#define BIG_IMG_HEIGHT 300.0
@interface DetailViewController ()
{
    NSArray *arraySett;
    NSArray *sectionTitles;
    AppDelegate *appDelegate;
    NSArray * imagesDuiCuo;
    int headerSection[5];
   
                        UIView *background;
}
@end

@implementation DetailViewController
@synthesize entity;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

-(UIImage *)imageFormImage:(UIImage*)image inRect:(CGRect)rect
{
    CGImageRef sourceImageRef = [image CGImage];
    CGImageRef newImageRef = CGImageCreateWithImageInRect(sourceImageRef, rect);
    UIImage *newImage = [UIImage imageWithCGImage:newImageRef];
    return newImage;
}

- (TIREntity*)getEntityCur
{
    appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    if (appDelegate.entityCurr == nil)
    {
        NSLog(@"error");
    }
   
    return appDelegate.entityCurr;
}

- (void)viewDidLoad
{
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000
    if ( [[[UIDevice currentDevice] systemVersion] doubleValue]>=7.0 )
    {
        self.edgesForExtendedLayout = UIRectEdgeNone;
        //self.extendedLayoutIncludesOpaqueBars = NO;
        //self.modalPresentationCapturesStatusBarAppearance = NO;
    }
#endif
   
    [super viewDidLoad];
    //0,不合格,1,合格,2,未检查
    imagesDuiCuo = [NSArray arrayWithObjects:[UIImage imageNamed:@"error.png"],[UIImage imageNamed:@"correct.png"],[NSNull null], nil];
   
    headerSection[0] = 60;
    headerSection[1] = 80;
    headerSection[2] = 100;
    headerSection[3] = 80;
    headerSection[4] = 120;
 // Do any additional setup after loading the view.
    [self createDetailData];
   
    AppDelegate *appDelegates=[[UIApplication sharedApplication] delegate];
    NSInteger navigationBarPadding=appDelegates.navigationBarPadding;
   
    NSUserDefaults *myDefaults = [NSUserDefaults standardUserDefaults];
    NSData* data = [myDefaults objectForKey:@"AppConfigToilet"];
    AppConfig* appConfig = [NSKeyedUnarchiver unarchiveObjectWithData:data];
    [self.labelSection setText:appConfig.sectionName];
   
    UIButton *lButton = [UIButton buttonWithType:UIButtonTypeCustom];
    lButton.frame = CGRectMake(0.0, 0.0, 37.0+navigationBarPadding, 44.0);
    [lButton setImage:[UIImage imageNamed:@"fanhui.png"] forState:UIControlStateNormal];
    [lButton addTarget:self action:@selector(actionBack) forControlEvents:UIControlEventTouchUpInside];
   
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithCustomView:lButton];
    leftButton.style = UIBarButtonItemStylePlain;
    self.navigationItem.leftBarButtonItem = leftButton;
}

- (void)actionBack
{
    [self.navigationController popViewControllerAnimated:YES];
}

-(NSMutableArray *)createArray:(int)indexSett
{
    NSArray *stepsStatus = [entity.stepsStatus objectAtIndex:indexSett];
    NSArray *stepsComments = [entity.stepsCommentsList objectAtIndex:indexSett];
    NSArray *stepsCommitTimesList = [entity.stepsCommitTimesList objectAtIndex:indexSett];
   
    int stepTimes = [stepsStatus count];
   
    NSMutableArray * arraySettChild = [NSMutableArray arrayWithCapacity:[stepsStatus count]];
   
    NSMutableArray * imagenamesList= [entity.stepsImagenamesLists objectAtIndexStrict:indexSett];
    for (int i=0;i<stepTimes;i++)
    {
        DetailTableViewCell *cell1 = [self createMyCell];
        UIImage *img = [imagesDuiCuo objectAtIndexStrict:[[stepsStatus objectAtIndexStrict:i] intValue]];
        [cell1.imageDuiCuo setImage:img];
       
        NSString *comment = [stepsComments objectAtIndexStrict:i];
        [cell1.labelDescription setText:comment];
       
        //shijian
        NSString *time = [stepsCommitTimesList objectAtIndexStrict:i];
        [cell1.labelTime setText:time];
       
        [cell1.labelCheckTimes setText:[NSString stringWithFormat:@"第%d次检查结果",(i+1)]];
       
        cell1.imageViewArray = [NSArray arrayWithObjects:
                                cell1.imageView1,
                                cell1.imageView2,
                                cell1.imageView3,
                                cell1.imageView4,
                                nil];
        if ([imagenamesList isKindOfClass:[NSArray class]])
        {
            if([imagenamesList count] > i)
            {
                NSArray * imagenames = [imagenamesList objectAtIndexStrict:i];
                if ([imagenames count]>0)
                {
                    for (int indexImage=0;indexImage<[imagenames count];indexImage++)
                    {
                        if ([imagenames objectAtIndexStrict:indexImage] != [NSNull null])
                        {
                            UIImage *image = [PicProcess readImage:[imagenames objectAtIndexStrict:indexImage]];
                            [[cell1.imageViewArray objectAtIndexStrict:indexImage] setImage:image];
                           
                            //lv start
                            [[cell1.imageViewArray objectAtIndexStrict:indexImage] setUserInteractionEnabled:YES ];
                            UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
                            [[cell1.imageViewArray objectAtIndexStrict:indexImage] addGestureRecognizer:singleTap];
                            //lv
                        }
                    }
                }
            }
        }
        [arraySettChild addObject:cell1];
    }
    return arraySettChild;
}

 

//点击事件 不修改原来的view
- (void)handleSingleTap:(UIGestureRecognizer *)gestureRecognizer {
    UIView *temview=[gestureRecognizer view];
    UIImageView * imagePicView = (UIImageView*)temview;
    //创建灰色透明背景,使其背后内容不可操作
    float screenHeight = [UIScreen mainScreen].bounds.size.height;
    float screenWidth = [UIScreen mainScreen].bounds.size.width;
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];
    background = bgView;
    [bgView setBackgroundColor:[UIColor colorWithRed:0.3
                                               green:0.3
                                                blue:0.3
                                               alpha:0.7]];
    [self.view addSubview:bgView];
   
    //创建边框视图
    UIView *borderView = [[UIView alloc] initWithFrame:CGRectMake(0, 10,BIG_IMG_WIDTH+16, BIG_IMG_HEIGHT+16)];
   
    //将图层的边框设置为圆脚
    borderView.layer.cornerRadius = 8;
    borderView.layer.masksToBounds = YES;
    //给图层添加一个有色边框
    borderView.layer.borderWidth = 8;
    borderView.layer.borderColor = [[UIColor colorWithRed:0.9
                                                    green:0.9
                                                     blue:0.9
                                                    alpha:0.7]CGColor];
   
   
    [bgView addSubview:borderView];
   
    //创建关闭按钮
    UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [closeBtn setImage:[UIImage imageNamed:@"guanb@2x.png"] forState:UIControlStateNormal];
    [closeBtn addTarget:self action:@selector(closePicView) forControlEvents:UIControlEventTouchUpInside];
    NSLog(@"borderview is %@",borderView);
    [closeBtn setFrame:CGRectMake(borderView.frame.origin.x+borderView.frame.size.width-20, borderView.frame.origin.y-6, 26, 27)];
    [bgView addSubview:closeBtn];
   
    //创建显示图像视图
    UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(8, 8, BIG_IMG_WIDTH, BIG_IMG_HEIGHT)];
   
    [imgView setImage:imagePicView.image];
    [borderView addSubview:imgView];
}
//图片预览关闭
-(void)closePicView
{
    [background removeFromSuperview];
}

 

-(void)createDetailData
{
    entity = [self getEntityCur];
   
    NSString *title1 = @"1.沉池结构闭水检验";
    NSString *title2 = @"2.二次侧排水及第一道防水涂料检查";
    NSString *title3 = @"3.回填检查(旁边及隐蔽验收)";
    NSString *title4 = @"4.二次防水检查";
    NSString *title5 = @"5.试面及门框安装完成后的试水检验";
   
    sectionTitles = [[NSArray alloc] initWithObjects:title1,title2,title3,title4,title5, nil];
   
    NSMutableArray *arraySett01 = [self createArray:0];
    NSMutableArray *arraySett02 = [self createArray:1];
    NSMutableArray *arraySett03 = [self createArray:2];
    NSMutableArray *arraySett04 = [self createArray:3];
    NSMutableArray *arraySett05 = [self createArray:4];
   
    arraySett = [[NSArray alloc] initWithObjects:arraySett01,arraySett02,arraySett03,arraySett04,arraySett05, nil];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 135;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [arraySett count];
}

-(DetailTableViewCell *)createMyCell
{
    NSString *identifierDetailCell = @"detailCell";
    DetailTableViewCell *cell = [self.myTableView dequeueReusableCellWithIdentifier:identifierDetailCell];
   
    if (cell == nil)
    {
        NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"DetailTableViewCell" owner:self options:nil];
        cell = [array objectAtIndex:0];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    return cell;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DetailTableViewCell *cell = [[arraySett objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
   
    return cell;
}

/*
-(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    //return [sectionTitles objectAtIndex:section];
}*/

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSArray *tempArray = [arraySett objectAtIndex:section];
    return [tempArray count];
}

-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIImageView *view = [[UIImageView alloc] init];
    UIImage *imageBg = [self imageFormImage:[UIImage imageNamed:@"appbg.png"] inRect:CGRectMake(0, 0, 320, headerSection[section])];
    [view setImage:imageBg];
    UILabel * label01 = [[UILabel alloc] initWithFrame:CGRectMake(21, 2, 280, 20)];
    [label01 setText:[sectionTitles objectAtIndex:section]];
    label01.font = [UIFont systemFontOfSize:16];
    label01.backgroundColor = [UIColor clearColor];
    [view addSubview:label01];
   
    UILabel * label02 = [[UILabel alloc] initWithFrame:CGRectMake(41, 22, 280, headerSection[section]-30)];
    [label02 setText:[appDelegate.stepContents objectAtIndex:section]];
    label02.font = [UIFont systemFontOfSize:12];
    label02.backgroundColor = [UIColor clearColor];
    [label02 setNumberOfLines:0];
   
    UIImageView *lvxianView = [[UIImageView alloc] initWithFrame:CGRectMake(11, 0, 2, headerSection[section])];
    UIImage *lvxian = [self imageFormImage:[UIImage imageNamed:@"lvxian.png"] inRect:CGRectMake(0, 0, 2, headerSection[section])];
    [lvxianView setImage:lvxian];
    [view addSubview:lvxianView];
   
    UIImageView *duiCuoView = [[UIImageView alloc] initWithFrame:CGRectMake(290, 4, 15, 15)];
    NSArray *stepStatus = [entity.stepsStatus objectAtIndex:section];
    if ([stepStatus count]>0)
    {
        UIImage *img = [imagesDuiCuo objectAtIndex:[[stepStatus objectAtIndex:([stepStatus count] - 1)] intValue]];
        [duiCuoView setImage:img];
        [view addSubview:duiCuoView];
    }
   
    [view addSubview:label02];
    return view;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return headerSection[section];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

0 0
原创粉丝点击