Hittest事件问题 [英] Hittest event problem

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

问题描述

我正在开发一个iPhone应用程序,其中包含带有webview的一系列视图.这些视图放置在滚动视图中.现在我的问题是我需要水平滚动滚动视图才能移至下一个视图,需要垂直滚动webview来查看其内容.我使用了webview的"hittest"事件来捕获touch事件并适当地路由该事件.现在,我需要在找到移动方向后从视图的touchesmoved函数中触发hittest事件(如果用户垂直触摸,则垂直移动Web视图滚动条;如果用户水平触摸,则显示下一个视图).我搜索了很多解决方案.寻找解决方案请提供帮助.预先感谢

I am developing an application for iPhone which contains a series of views with webview .These views are placed in a scroll view .Now my problem is that i need to scroll the scroll view horizontally to move to the next view ,also i need to scroll the webview vertically to view its contents .I used "hittest" event of webview to capture the touch event and route the event appropriately .Now i need to fire the hittest event from touchesmoved function of the view after finding the direction of move(move webview scroll bar vertically if user touched vertically or show the next view if user touched horizontally) .I searched a lot for a solution ..Looking for a solution please help.. Thanks in advance

推荐答案

我不确定我是否完全理解这个问题,但是如果您希望在类之间进行通信,则可以使用NSNotificationCenter.这样,当某些事件发生时,这两个视图可以进行通信.

I'm not sure I fully understand the question but if you are looking to communicate between classes you can use NSNotificationCenter. This way the two views can communicate when certain events happen.

如果您不熟悉NSNotificationCenter,我将对其进行简要说明.

If you are unfamiliar with NSNotificationCenter I'll explain it briefly.

在这两个类中,通常都可以在初始化方法中设置观察者,如下所示:

In both classes you would set up observers, usually in your initialisation method, like so:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:nil object:nil];

因此,在完成此操作的类中,您将需要一种方法来处理通知.在这里,我称它为:

So in the classes where you have done this, you will need a method to handle the notifications. Here I've called it:

handleNotification:(NSNotification *)notification {}

然后,每次您要传达消息时,只需发布​​一条通知:

Then, each time you want to communicate a message, just post a notification:

[[NSNotificationCenter defaultCenter] postNotificationName:@"aName" object:nil];

如您所见,您可以为消息命名并传递一个对象,可以使用

As you can see you can give the message a name and pass an object, which can be retrieved at the other end in your handleNotification method by using

NSString *name = (NSString *)[notifcation name];
id object = [notification object];

这篇关于Hittest事件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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