ios - UIImageView finding how much is out of bounds -
i'm scaling image within uiimageview using : uiviewcontentmodescaleaspectfill
the image scales nicely issue imageview sits within uiscrollview, i've set origin 0,0. fine majority of images i'm using have greater height , push out of bounds. don't want trim image, i'd dynamically push uiimageview frame down on y axis based off amount that's out of bounds.
how can go finding out what's out of bounds on y axis / height? excuse poor code example.
nsstring *imageurl = [self.detailitem objectforkey:@"job_header"]; animage = [[uiimageview alloc] initwithframe:cgrectmake(0, 0, max_height, 118)]; animage.contentmode = uiviewcontentmodescaleaspectfill; [animage setimagewithurl:[nsurl urlwithstring:imageurl] placeholderimage:[uiimage imagenamed:@"placeholder.png"] completed:^(uiimage *image, nserror *error, sdimagecachetype cachetype) { //adjust frame once image loaded [self adjustpositions]; }]; within adjustposition:
if (animage.image.size.height > max_height) { cgrect myframe = animage.frame; myframe.origin.y = 100; myframe.origin.y = animage.frame.size.height / animage.image.size.height; animage.frame = myframe; } i'm using: sdwebimage, , q relevant , may explain issue little bit better: uiimageview, setclipstobounds , how images losing head
please note don't want clip bounds @ all. want preserve bounds , move origin true (0,0) position.
here method can calculate size of image in image view. originalsize size of image , constraint image view size.
- (cgsize) size: (cgsize) originalsize constrainedtosize: (cgsize) constraint { cgfloat ratiooriginal = originalsize.width/originalsize.height; cgfloat ratioconstraint = constraint.width/constraint.height; cgsize resultingsize = cgsizezero; if (ratioconstraint >= ratiooriginal) { resultingsize = cgsizemake(constraint.width, originalsize.height*constraint.width/originalsize.width); }else{ resultingsize = cgsizemake(constraint.height*originalsize.width/originalsize.height, constraint.height); } return resultingsize; } having size of image in image view can calculate how of image out of bounds.
Comments
Post a Comment