我为UIButton添加了PanGestureRecognizer,
我不明白以下几点:
- (IBAction)handlePan:(UIPanGestureRecognizer *)recognizer {
switch([recognizer state]){
case UIGestureRecognizerStateBegan: {
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:recognizer.view.frame];
[button setBackgroundColor: [UIColor redColor]];
// [self.view insertSubview:button belowSubview:recognizer.view];
_tempButton = button;
}break;
case UIGestureRecognizerStateChanged: {
CGPoint translation = [recognizer translationInView:self.view];
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x, recognizer.view.center.y + translation.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:self.view];
}break;
}
}
在上面的例子中,一切顺利。开始。停止。从先前位置拖动。
但如果我取消注释这些行
// [self.view insertSubview:button belowSubview:recognizer.view];
发生了一些奇怪的事情
1)开始拖动UIButton。红色的uibutton被添加到视图中。 NORMAL
为什么?