小编von*_*ron的帖子

UITapGestureRecognizer在动画子视图上没有响应

我有一个简单的程序,可以创建一个子视图并在屏幕上设置动画.

作为该程序的一部分,我想在点击子视图时添加功能.我使用以下方法创建子视图,添加UITapGestureRecognizer,然后为子视图设置动画:

int randomName = arc4random() % ([pieceNames count] - 1);
int animationDuration = arc4random() %  5 + 5 ;
NSString *randomPiece = [pieceNames objectAtIndex:randomName];

float yStart = arc4random() % 650;
float yEnd = arc4random() % 650;

UIView *piece = [[PieceView alloc]initWithFrame:CGRectMake(100.0, yStart, 75.0, 75.0)];
[piece setValue:randomPiece forKey:@"name"];

UITapGestureRecognizer *recognizer = [[UITapGestureRecognizer alloc]initWithTarget:self
                                                                            action:@selector(handleTouch:)];
[piece addGestureRecognizer:recognizer];

[[self view] addSubview:piece];

[UIView animateWithDuration:animationDuration
                      delay:0.0
                    options:UIViewAnimationOptionAllowUserInteraction
                 animations:^(void){
                     piece.center = CGPointMake(950.0, yEnd);
                 } completion:^(BOOL done){
                     [piece removeFromSuperview];
                 }];
Run Code Online (Sandbox Code Playgroud)

以下是处理点按的代码:

PieceView *pv = (PieceView *) …
Run Code Online (Sandbox Code Playgroud)

uiviewanimation ios uitapgesturerecognizer

3
推荐指数
1
解决办法
899
查看次数