如何将触摸事件传递给另一个对象?
我引用了名为“Comic Strip”和“Balloon Stickies Free”的应用程序,
当我添加语音气球并触摸某人或某人的尾巴时,它会起作用。但是当我触摸某人和某人的尾巴周围或之间的尾巴时,它不起作用。 Photo 得到触摸并在 sb 下面工作
,所以我尝试使用 hitTest:withEvent。
当我第一次触摸矩形或 tailRect 时,它可以工作。但是当我触摸对象中的其他位置,然后再次触摸矩形或 tailRect 时,它不起作用。
那么如何修改这段代码呢?我不知道..请帮助我
- (id)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *hitView = [super hitTest:point withEvent:event];
if(CGRectContainsPoint(rectangle, currentPt)==YES || CGRectContainsPoint(tailRect, currentPt)==YES)
return hitView;
else
return nil;
}
I referenced the apps called "Comic Strip" and "Balloon Stickies Free"
When i add a speech balloon and touch s.b or s.b's tail, it works. But when i touch tail's around or between s.b and s.b's tail, it doesn't work. And Photo gets touch and works below the s.b.
So i tried to use hitTest:withEvent.
It works when i touch rectangle or tailRect first time. But when i touch other place in the object, and i touch rectangle or tailRect again, it doesn't work.
So how to modify this code ? i don't know .. help me please
- (id)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *hitView = [super hitTest:point withEvent:event];
if(CGRectContainsPoint(rectangle, currentPt)==YES || CGRectContainsPoint(tailRect, currentPt)==YES)
return hitView;
else
return nil;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅这篇文章水平滚动。使用此代码,您可以在单个 UIWindow 类中获取所有触摸事件。您必须编写一些代码来适当地传递控制权。
See this post horizontal scrolling. Using this code you can get all touch events in a single UIWindow class. You have to write some code to pass control appropriately.
尝试改写
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
。或者看看 Ole Begemann 的 OBShapedButton。代码可以轻松修改
使用 UIView 而不是 UIButton。
Try overriding
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
instead.Or take a look at Ole Begemann's OBShapedButton. Code can easily be modified
to work with UIView instead of UIButton.