基本的に、パンジェスチャを使用してセルをスワイプすると表示されるカスタムの削除ボタンを備えたUITableViewCellクラスがあります。
このようなもの。_delBtnは私の削除ボタンです。クリックすると、TableCellが削除されます。これで私を助けてください
- (void)handlePan:(UIPanGestureRecognizer *)recognizer
{
CGPoint translation = [recognizer translationInView:self];
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x, recognizer.view.center.y);
[recognizer setTranslation:CGPointMake(0, 0) inView:_baseView];
if (recognizer.state == UIGestureRecognizerStateEnded)
{
translation.y = 0;
CGPoint velocity = [recognizer velocityInView:_baseView];
CGFloat magnitude = sqrtf((velocity.x * velocity.x));
CGFloat slideMult = magnitude / 1000;
NSLog(@"magnitude: %f, slideMult: %f", magnitude, slideMult);
float slideFactor = 0.1 * slideMult;
velocity.x = velocity.x + 1000;
velocity.y = 0;
CGPoint finalPoint = CGPointMake(recognizer.view.center.x + (velocity.x * slideFactor),
recognizer.view.center.y + (velocity.y * slideFactor));
finalPoint.x = MIN(MAX(finalPoint.x, 0), _baseView.bounds.size.width);
finalPoint.y = MIN(MAX(finalPoint.y, 0), _baseView.frame.size.height);
[UIView animateWithDuration:slideFactor*2 delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
recognizer.view.center = finalPoint;
} completion:nil];
if (finalPoint.x >= 195)
{
_delBtn = [[UIButton alloc] initWithFrame:CGRectMake(5, 10, 60, 60)];
[_delBtn setImage:[UIImage imageNamed:@"delBtn3.jpg"] forState:UIControlStateNormal];
[_delBtn addTarget:self action:@selector(deleteClicked) forControlEvents:UIControlEventTouchUpInside];
_delBtn.hidden = NO;
[_baseView insertSubview:_delBtn atIndex:0];
_delBtn.alpha = 0;
[UIView animateWithDuration:slideFactor delay:0.4 options:UIViewAnimationOptionCurveLinear animations:^{
recognizer.view.center = finalPoint;
} completion:nil];