user1412469
user1412469

Reputation: 279

Disabling scrolling when image is zoomed

I have an image inside a UIScrollView. What I want to happen is if I zoomed in to a particular position, I want to disable the scrolling (both vertical and horizontal) so that it will remain on the zoomed area. Can you give me any ideas on how to do this?

Upvotes: 0

Views: 108

Answers (1)

Rui Peres
Rui Peres

Reputation: 25907

Two things to keep in mind:

  1. Make sure you are exactly where you want when you need to disable the scroll. (you can use some methods from the UIScrollViewDelegate to accomplish that).
  2. Make the contentSize of your UIScrollView the same size of your frame. This way both the horizontal and the vertical scroll will be disable.

CGRect myScrollViewRect = myScrollView.frame;
CGSize myScrollViewFrameSize = CGSizeMake(myScrollViewRect.frame.size.width, myScrollViewRect.frame.size.height);
myScrollView.contentSize = myScrollViewFrameSize;

For clarity I putted more code than you would normally need to.

Upvotes: 1

Related Questions