我有一个 UIButton 将 draginside 事件发送到:
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
它通过 viewDidLoad 中的以下代码执行此操作:
[colourButton1 addTarget:self action:@selector(touchesBegan:withEvent:) forControlEvents:UIControlEventTouchDown];
在它发送到的方法中,有以下行:
UITouch *myTouch = [touches anyObject];
并且由于某种原因,当在 UIButton 内拖动时,这会使应用程序崩溃。任何想法为什么?
编辑:解决方案..
-(IBAction)buttonDragged:(id)button withEvent:(UIEvent*)event {
NSSet *touches = [event touchesForView:colourButton1];
[self touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event];
}