我有一个父类(A),它是UIViewController。比我创建B类是类A的子类。发生什么事是我不能用类似touchesBegan的方法在类B中捕捉触摸事件。但是如果我在类A中实现这个方法......他们会被调用。UIViewController的子类不捕捉触摸事件
@interface A:UIViewController
.....
@interface B:A
我有一个父类(A),它是UIViewController。比我创建B类是类A的子类。发生什么事是我不能用类似touchesBegan的方法在类B中捕捉触摸事件。但是如果我在类A中实现这个方法......他们会被调用。UIViewController的子类不捕捉触摸事件
@interface A:UIViewController
.....
@interface B:A
你需要实现你的UIView
子类的方法,而不是在UIViewController
子类。
您需要继承UIView以实现touchesBegan方法。
@interface YourCustomView : UIView
@implementation YourCustomView
// Override this function to get the touch
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"TOUCH!");
}
现在设置你的VC的观点作为 “YourCustomView”
@interface YourViewController : UIViewController
{
YourCustomView* view
}
要使用一个UIViewController,必须做的事件,如:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch;
CGPoint pos;
for(touch in touches)
{
//pos = [ touch locationInView:self ]; // Only work on UIView
pos = [touch locationInView:self.view ]; // Work on UIViewController
//NSLog(@"Touch: %f, %f",pos.x,pos.y);
// Send X, Y, tapcount
_faceOff->toucheBegan(pos.x, pos.y, [ [ touches anyObject ] tapCount ]);
}
}
希望它能帮助。
嗯...我想我不明白。我在我的问题中添加了更多信息。 – troner 2010-09-29 15:17:07
现在一切正常。这是我的错误。我有一些错误。我的子类工程:)谢谢你的回答! – troner 2010-09-29 16:30:54