Touch Events in UIScroll View in iPhone

巧了我就是萌 提交于 2019-12-12 05:58:06

问题


I have created scroll view in my view controller 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!


回答1:


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.



来源:https://stackoverflow.com/questions/3602996/touch-events-in-uiscroll-view-in-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!