iphone - Click a imageview popup a view showing the original image -
i have loaded several images table view. image has been resized, , want when user tap on imageview, pops view showing original image size, , when user click again anywhere, view disappears , tableview. code loads image this:
- (uitableviewcell *)tableview:(uitableview *)atableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *cellidentifier = @"cell"; searchcell *cell = (searchcell *)[atableview dequeuereusablecellwithidentifier:cellidentifier]; if (!cell) { cell = [[[nsbundle mainbundle] loadnibnamed:@"searchcell" owner:self options:nil] objectatindex:0]; } cell.selectionstyle = uitableviewcellselectionstylenone; cell.name.text = [[self.brands objectatindex:indexpath.row] objectforkey:@"name"]; __weak searchcell *weakcell = cell; [cell.leftimageview setimagewithurlrequest:[nsurlrequest requestwithurl:[nsurl urlwithstring:[nsstring stringwithformat:@"http://s-57130.gotocdn.com/%@", [[self.brands objectatindex:indexpath.row] objectforkey:@"pic"]]]] placeholderimage:[uiimage imagenamed:@"app_icon.png"] success:^(nsurlrequest *request, nshttpurlresponse *response, uiimage *image) { cgfloat imageheight = image.size.height; cgfloat imagewidth = image.size.width; cgsize targetsize = cgsizemake(70, 70); cgsize newsize = targetsize; cgfloat scalefactor = targetsize.width / imagewidth; newsize.height = imageheight * scalefactor; uigraphicsbeginimagecontextwithoptions(newsize, no, 0.0); [image drawinrect:cgrectmake(0, 0, newsize.width, newsize.height)]; uiimage *small = uigraphicsgetimagefromcurrentimagecontext(); uigraphicsendimagecontext(); weakcell.imageview.image = small; } failure:^(nsurlrequest *request, nshttpurlresponse *response, nserror *error) { }]; return cell; }
no need resize image manually. if set imageview
contentmode
property uiviewcontentmodescaleaspectfill
, automatically scale fit size of image view.
as scaling on tap, check out uiimageviewmodescaleaspect.
Comments
Post a Comment