views:

35

answers:

2

Hi,

I am creating an iPhone application and I have a UIScrollView. I'd like to ask how to detect that the imageview is in the middle of the page to display its label below the UIscrollview.

Thanks!

+1  A: 

hmm, you'd have to make your class conform to the UIScrollViewDelegate then use:

– scrollViewWillBeginDragging: to set an NSTimer to run a method which will check if myImage.center == myScrollView.center and then use – scrollViewDidEndDecelerating: to stop the timer.

Thomas Clayson
thank you for your reply. Is there an easier way how to detect the image in the centre, something which doesn't go through all the images and checks if they are in the centre?
Lily
is this some sort of gallery script? why don't you put paging on and then you can work out what "page" you are on (using `- scrollViewDidEndDecelerating` to get the current offset and divide by the frame.size.width) then look up the image details from an array, or something?
Thomas Clayson
thanks i'll read about paging. thanks a lot!
Lily
A: 

When you are scrolling your scroll view, a method of UIScrollViewDelegate will be called repeatedly during scrolling.

- (void)scrollViewDidScroll:(UIScrollView *)scrollView;

You can get the current context offset by scrollView's property.

- scrollViewWillBeginDragging and -scrollViewDidEndDecelerating won't be called, if you scroll the view by commands, which are in the UIScrollView class.

Toro