我已经在我的项目中实现了这个自定义控件:Github 页面这个控件添加了一个像滑动到删除/完成功能的邮箱,我想使用它。
我在使用它时遇到的唯一问题是,如果我通过情节提要向单元格添加 UITextField。当我添加一个单元格时,它会停止识别手势,只允许我与 UITextField 交互。
有没有人可以解决这个问题?
编辑:这是 TableViewCell 的初始化方法。对不起。
- (void)initializer
{
_mode = MCSwipeTableViewCellModeSwitch;
_colorIndicatorView = [[UIView alloc] initWithFrame:self.bounds];
[_colorIndicatorView setAutoresizingMask:UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth];
[_colorIndicatorView setBackgroundColor:[UIColor clearColor]];
[self insertSubview:_colorIndicatorView belowSubview:self.contentView];
_slidingImageView = [[UIImageView alloc] init];
[_slidingImageView setContentMode:UIViewContentModeCenter];
[_colorIndicatorView addSubview:_slidingImageView];
_panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePanGestureRecognizer:)];
[self addGestureRecognizer:_panGestureRecognizer];
[_panGestureRecognizer setDelegate:self];
}
以及处理手势的方法
- (void)handlePanGestureRecognizer:(UIPanGestureRecognizer *)gesture
{
UIGestureRecognizerState state = [gesture state];
CGPoint translation = [gesture translationInView:self];
CGPoint velocity = [gesture velocityInView:self];
CGFloat percentage = [self percentageWithOffset:CGRectGetMinX(self.contentView.frame) relativeToWidth:CGRectGetWidth(self.bounds)];
NSTimeInterval animationDuration = [self animationDurationWithVelocity:velocity];
_direction = [self directionWithPercentage:percentage];
if (state == UIGestureRecognizerStateBegan)
{
}
else if (state == UIGestureRecognizerStateBegan || state == UIGestureRecognizerStateChanged)
{
CGPoint center = {self.contentView.center.x + translation.x, self.contentView.center.y};
[self.contentView setCenter:center];
[self animateWithOffset:CGRectGetMinX(self.contentView.frame)];
[gesture setTranslation:CGPointZero inView:self];
}
else if (state == UIGestureRecognizerStateEnded || state == UIGestureRecognizerStateCancelled)
{
_currentImageName = [self imageNameWithPercentage:percentage];
_currentPercentage = percentage;
MCSwipeTableViewCellState state = [self stateWithPercentage:percentage];
if (_mode == MCSwipeTableViewCellModeExit && _direction != MCSwipeTableViewCellDirectionCenter && [self validateState:state])
[self moveWithDuration:animationDuration andDirection:_direction];
else
[self bounceToOriginWithDirection:_direction];
}
}