我希望在我的用户触摸屏幕时运行一些方法,因此在我的ViewController中实现了touchesBegan:withEvent:方法,但是当我将滚动视图拖放到我的iphone上时,不再使用touchesBegan:withEvent:方法被叫。
尝试修复我在ViewController中实现了becomeFirstResponder方法并将其告诉return YES;
然后在viewDidAppear方法中调用[self becomeFirstResponder];
我也尝试创建一个自定义滚动视图并在其中创建一个ViewController对象属性,然后在touchesBegan:withEvent:方法中为我的自定义滚动视图我实现它[self.mainViewController touchesBegan:withEvent]
所以希望每次我触及屏幕上我的自定义滚动视图上的touchesBegan方法将被调用,然后因为我的vc中的touchesBegan方法将被调用,但这也无济于事。
我还向我的vc创建了一个滚动视图的插座,并添加了一个轻敲手势识别器,并用一个方法和东西启动它,并且我用它启动的方法有效但是只有在我触摸后它才被调用在屏幕内部,我希望在我触摸屏幕时立即调用该方法
任何答案都非常感谢!
答案 0 :(得分:3)
覆盖触摸结束,如果用户点击而不是拖动,我手动将消息转发给第一响应者。
@interface MyScrollView : UIScrollView {
}
@end
@implementation MyScrollView
- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event {
if (!self.dragging) {
[self.nextResponder touchesEnded: touches withEvent:event];
}
[super touchesEnded: touches withEvent: event];
}
@end
答案 1 :(得分:0)
为了做到这一点,我只创建了自己的自定义滚动视图类,并使用我制作的委托方法在uiscroll视图中实现了touchesBegan:withEvent:方法。
所以基本上我只需要使用委托。