Detect WHAT image is actually displaying in a ScrollView
Hi Guys,
I'm getting creazy with this problem.
I put a series of images (named 1.jpg,2.jpg.....) in a scrollview.
Then I simply need to know WHAT image is actualy on the display.....
Example: I have 10 images... I scroll images and stop at image 7....
How can I obtain that "7"???
I've tryed to use ScrollViewDidEndDragging
and ScrollViewDidEndDecelerating mothods and in both of them I've
inserted the code: myNumber = myScrollview.tag
But All I get is always ZERO! (the number "0")
It means that all images are tagged with zero???
HAve you got a solution for this?
I will really appreciate it!
I don't know. But I would guess not. I would assume the scroll view has 0 for its tag until you set it to otherwise as well.
This may not be the easiest or most fool proof way, but you could always just use contentOffset property to see where the scroll view is at and then compare that to your image locations to figure out which one they are viewing.
I don't know. But I would guess not. I would assume the scroll view has 0 for its tag until you set it to otherwise as well.
This may not be the easiest or most fool proof way, but you could always just use contentOffset property to see where the scroll view is at and then compare that to your image locations to figure out which one they are viewing.
If I know the direction of the scroll (left or right) I could increase/decrease a counter to determinate what is my images?
Do you think it could be an easy way to do it?
However have you got a suggestion for alternative way to recognize what image is displayed in a scrollview?
That might be an easy way to do it if you could figure out how to tell when to increment and decrement the counter.
The only suggestion I can think of is, as I mentioned before, comparing the contentOffset property to your various images to see which is currently on the screen. It will take a little math but it could definitely get the job done.
Edit: To be a bit more clear, you could compare the contentOffset and contentSize with the frame.origin and frame.size of each image to see which is on the screen.
That might be an easy way to do it if you could figure out how to tell when to increment and decrement the counter.
The only suggestion I can think of is, as I mentioned before, comparing the contentOffset property to your various images to see which is currently on the screen. It will take a little math but it could definitely get the job done.
Edit: To be a bit more clear, you could compare the contentOffset and contentSize with the frame.origin and frame.size of each image to see which is on the screen.
Hi Jamvert,
thanks again for your suggestion.
Do you have any code sample about how to use contentSize and OffSet property?
I'm very new about objective-C and I'm a little confused on how use contentSize...
I was thinking also to add to the scrollview a view for every image and then in that view add the image and a button ... not so elegant but it should work... ??
To set the content size you just have to do something like this, except with whatever dimensions you need to fit your whole content, I am not sure if you can do it automatically in interface builder or not: