ios - UIScrollView and UIImageView - move horizontaly -
ios - UIScrollView and UIImageView - move horizontaly -
i have uiscrollview uiimageview on it. set image in code , can have different width (height same). want scrollable (eg. see part of , drag left / right see rest).
i have code performed after image change:
float x = self.imageview.frame.origin.x; float y = self.imageview.frame.origin.y; float w = scaleimg.size.width; float h = scaleimg.size.height; self.imageview.frame = cgrectmake(x, y, w, h); self.imageview.bounds = cgrectmake(0, 0, w, h); w = self.frame.size.width; h = self.scrollview.frame.size.height; [self.scrollview setcontentsize: cgsizemake(w + 20, h)]; problem is, didnt scroll correctly (i think didnt scroll @ all). , after scroll, image resized, not respect frame have set above.
i using ios7, storyboard, autolayout.
if want image fit scrollview , scrollable left , right should create image view height same scrollview , width scaled accordingly image. seek this:
uiimage *image; uiscrollview *scrollview; uiimageview *imageview; imageview = [[uiimageview alloc] initwithframe:cgrectmake(.0f, .0f, scrollview.frame.size.height*image.size.width/image.size.height, scrollview.frame.size.height)];//fixed height imageview.image = image; imageview.contentmode = uiviewcontentmodescaletofill; [scrollview addsubview:imageview]; scrollview.contentsize = imageview.frame.size; scrollview.contentoffset = cgpointmake((scrollview.contentsize.width-scrollview.frame.size.width)*.5f, .0f);//scroll center note designed images have proportionally larger width scrollview. if not case should create specific logic other images (either background visible or scrollable in y coordinate).
ios objective-c uiscrollview uiimageview
Comments
Post a Comment