我有一个有很多物体的UIView。我也有像这样的touchesMoved的实现:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"move");
}
我最近想要滚动视图,所以我只是打开了UIView,并在Interface Builder中将其对象类更改为UIScrollView。但是,现在即使触摸屏幕也不会调用'touchesMoved'方法。
有人可以帮我搞动一下再次移动吗?我不知道我做了什么来打破它!
编辑:我试过跟this guide,但我可能做错了。从阅读其他帖子看起来UIScrollView似乎无法接受触摸事件本身,他们需要被发送到响应链?我将非常感谢任何可以帮助指导我解决这个问题的人...当我意识到UIScrolView杀死我的触摸检测时,我的应用程序就准备提交了! (我刚刚将我的应用程序UIView更改为UIScrollView以允许与iPhone 4兼容)。答案 0 :(得分:3)
我刚刚在您的编辑中看了the guide,我想我可以看到问题所在。有关类似问题,请参阅this answer。
您的UIScrollView
子类看起来像这样:
#import "AppScrollView.h"
@implementation AppScrollView
- (id)initWithFrame:(CGRect)frame
{
return [super initWithFrame:frame];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"AppScrollView touchesEnded:withEvent:");
// If not dragging, send event to next responder
if (!self.dragging)
[[self.nextResponder nextResponder] touchesEnded:touches withEvent:event];
else
[super touchesEnded: touches withEvent: event];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"AppScrollView touchesMoved:withEvent:");
[[self.nextResponder nextResponder] touchesMoved:touches withEvent:event];
}
@end
包含AppScrollView
对象的类应该采用UIScrollViewDelegate
协议并实现这些方法:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"SomeClass touchesMoved:withEvent:");
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"SomeClass touchesEnded:withEvent:");
}
然后记录的输出将如下所示:
2013-06-11 10:45:21.625 Test[54090:c07] AppScrollView touchesMoved:withEvent:
2013-06-11 10:45:21.625 Test[54090:c07] SomeClass touchesMoved:withEvent:
2013-06-11 10:45:21.642 Test[54090:c07] AppScrollView touchesMoved:withEvent:
2013-06-11 10:45:21.642 Test[54090:c07] SomeClass touchesMoved:withEvent:
2013-06-11 10:45:21.655 Test[54090:c07] AppScrollView touchesEnded:withEvent:
2013-06-11 10:45:21.656 Test[54090:c07] SomeClass touchesEnded:withEvent: