sash
sash

Reputation: 8725

Setting UIScrollView scroll area

I am making a custom crop image controller. UIScrollView is the main view in which I add scroll content (UIImageView). Scrolling and zooming works good, but what I want to do now is to add a crop area so a user can scroll/zoom image inside that area. I added UIView on top of everything just to indicate the crop area. If I set the UIScrollView frame to fit screen size (see picture 1) then user is not able to scroll the top of the content (yellow image) down so it alines with the to of the crop area (because image fits the UIScrollView, it is not scrollable). Picture 1: enter image description here

If I make the UIScrollView the size of the crop are (see picture 2), it works perfect except I can not see anything behind the scroll area (black colour). Picture 2: enter image description here

Is there any way to set the scroll area to crop area and leave the UIScrollView frame to fit screen size? Or should I approach the problem different?

Upvotes: 0

Views: 2289

Answers (1)

Alexander Kostiev
Alexander Kostiev

Reputation: 306

Consider adding Content Insets to scroll view, equal to the gaps from the top to the crop area and from the bottom of the scroll view to the bottom of the crop area.

[self.scrollView setContentInsets:UIEdgeInsetsMake(top, left, bottom, right)];

where top and bottom should be as follows:

CGFloat top = CGRectGetMinY(self.cropAreaView.frame);
CGFloat bottom = CGRectGetMaxY(self.cropAreaView.frame);

and left and right in your example are 0.

Upvotes: 2

Related Questions