Touch Events in UIScroll View in iPhone
I have created scroll view in my view contr开发者_开发问答oller and set the buttons in the scroll view. I have set the scroll view between the two images. The buttons are scrolling horizontally. Now i want to enable and disable the images. For Eg: Initially left images are to be hidden, once moving the button horizontally and enable right button and hidden the left button.
How can i write the touch events for the scroll view?.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"ImagePressed");
}
If i have used this method in my application. But the methods are doesn't called. SO how can i write the touch events when i clicks the scroll view. If i get the touch events, then only i could enable and disable the images. so please help me out?
See my images, (I have set the two images(left arrow and right arrow images)).
I have set the two images in the imageview and I have set the scroll view as subview for the custom view.(Scroll view is not subview for view controller).
UIImageView *leftImg;
UIImageView *rightImg;
Thanks!
I believe what you want to do can be achieved by setting a delegate
for your UIScrollView
.
Your view controller could implement UIScrollViewDelegate
methods like
- (void)scrollViewDidScroll:(UIScrollView *)sender
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate
And
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
and respond appropriately by checking the contentOffset
property on the scroll view.
精彩评论