在iPhone中触摸UIScroll视图中的事件 [英] Touch Events in UIScroll View in iPhone

查看:151
本文介绍了在iPhone中触摸UIScroll视图中的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在视图控制器中创建了滚动视图,并在滚动视图中设置了按钮。我已经设置了两个图像之间的滚动视图。按钮水平滚动。现在我想启用和禁用图像。例如:最初左侧的图像将被隐藏,一旦水平移动按钮并启用右键并隐藏左按钮。



我如何为滚动视图?

   - (void)touchesBegan:(NSSet *)触摸与事件:(UIEvent *)事件{
NSLog(@ImagePressed);
}

如果我在我的应用程序中使用了这种方法。但是这个方法是不叫的。那么当我点击滚动视图时,我如何写出触摸事件。如果我得到触摸事件,那么只有我可以启用和禁用图像。所以请帮帮我吗?



看到我的图像,(我已经设置了两个图像(左箭头和右箭头图像))。



我已经在图像视图中设置了两个图像,我已经将滚动视图设置为自定义视图的子视图(滚动视图不是视图控制器的子视图)。

  UIImageView * leftImg; 

UIImageView * rightImg;





谢谢!

解决方案

我相信你想做什么可以通过为您的 UIScrollView 设置委托来实现。
您的视图控制器可以实现 UIScrollViewDelegate 方法,如

 (void)scrollViewDidScroll:(UIScrollView *)sender 
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate((BOOL))减速
/ pre>

  (void)scrollViewDidEndDecelerating :( UIScrollView *)scrollView 

并通过检查 contentOffset 属性在滚动视图。


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!

解决方案

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.

这篇关于在iPhone中触摸UIScroll视图中的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆