ios - Zoom image using auto layout in scroll view How to center? -


i'm done zooming using auto layout storyboard, problem image not center after zoom. goal make picture zoom picture boundaries without black stripes.

here constraints (it's standard scrollview imageview): enter image description here

and here done in order. firstable set uiscrollviewdelegate methods:

-(uiview *)viewforzoominginscrollview:(uiscrollview *)scrollview{     return self.fullscreenimageview; } 

and after image download complete update height constraint of uiimageview:

-(void)setupconstraintstoimagesize:(cgsize)imagesize {     [self.imagehconstraint setconstant:imagesize.height];     [self layoutifneeded]; } 

for image constraints

enter image description here

so it's work (sorry 3mb gif) :

enter image description here

so it's almost works, it's strangely goes bottom, not center, how center it?

i figure out have sth method -(void)scrollviewdidzoom:(uiscrollview *)scrollview i'm not sure should set there.

eureka! managed autolayout

to achieve needs done create outlet center y constraints , modify when zoomed:

-(void)scrollviewdidzoom:(uiscrollview *)scrollview {     cgfloat diff = self.fullscreenimageview.frame.size.height-self.fullscreenimageview.image.size.height;     if(self.fullscreenimageview.frame.size.height >= self.frame.size.height) {return;}     [self.centeryconstraint setconstant:-diff/2]; } 

that's it.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -