我没有看到这里有什么问题。当用户点击并按住时,我添加一个视图,当触摸完成时,视图被删除。这不起作用,我确实看到 UIGestureRecognizerStateEnded 正在发送。
但是,如果我[tmpView removeFromSuperview];
在该状态之外调用它会被删除而没有任何问题。
知道是什么原因造成的吗?
-(void)longTapped:(UILongPressGestureRecognizer*)recognizer {
UIView *tmpView = [[UIView alloc] init];
tmpView.backgroundColor = [UIColor greenColor];
// Position the menu so it fits properly
tmpView.frame = CGRectMake(0, 100, 320, 250);
// Add the menu to our view and remove when touches have ended
if (recognizer.state == UIGestureRecognizerStateBegan) {
[self.view addSubview:tmpView];
}
else if(recognizer.state == UIGestureRecognizerStateEnded){
[tmpView removeFromSuperview];
}
}