I have one ScrollView which contains one imageView (created programmatically with addSubView) and one view, which contains segmented control to change pictures. I added gesture recognisers for zooming. Horizontal position of the segmented control is fixed. The problem occurs when I try to click on the segmented control and the image is zoomed too much. It doesn't work. If zoom level is small, it keeps working and changes between images.
Two screenshots below illustrate the situation: 1) when segmented control works and 2) when it doesn't work.
http://cs617220.vk.me/v617220757/e375/hvRdXNe9SBY.jpg http://cs617220.vk.me/v617220757/e36e/E4auq4-kFL4.jpg
I think, the problem is in hierarchy of views and when added subview doesn't overlap view with segmented control - it works, and when overlap - it stops. I tried to place imageView to the bottom, here is the code:
[self.scrollView addSubview:self.imageView];
[self.scrollView sendSubviewToBack:self.imageView];
But this does not help, the problem remains. How can I put imageView to the bottom of the stack?
Update to comment:
I have small UIView in between UIScrollView and segmented control. It seems, that I managed to catch the problem: it is the horizontal-fixing code. I used Reveal app to find this out. Two screenshots show the problem:
Here segmented control is placed just above small UIView. After zooming just a bit the screen looks like:
So, the UIView goes away as the rest of the picture and does not have fixed horizontal position. What is interesting, that if I put segmented control directly on the UIScrollView, it works, but position is not fixed horizontally. This is the code:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGRect frame = _floorSelector.frame;
frame.origin.x = scrollView.contentOffset.x;
_floorSelector.frame = frame;
}
And this doesn't work (if I try to fix position of UIView, not segmented control):
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGRect frame = _selectorView.frame;
frame.origin.x = scrollView.contentOffset.x;
_selectorView.frame = frame;
}
Solution:
Instead of blocking scrolling in one direction, I decided to get rid off all supplementary views and implement vertical scrolling for segmented view. The code is here:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGRect frame = _floorSelector.frame;
frame.origin.y = -scrollView.contentOffset.y;
_floorSelector.frame = frame;
}
And the view hierarchy as follows:
So, the segmented control is placed directly on main view, not the scroll view. When scrolling is being performed vertically, it scrolls too, but, when horizontally - it doesn't. Thank's for help.
As Departamento B helped me to solve this problem (it's his idea), I mark his answer with a tick.