我已经在我的项目中实现了此自定义控件:Github page此控件添加了一个像滑动一样的邮箱以删除/完成我想要使用的功能。UITextfield干扰滑动手势
我在使用这个时遇到的唯一问题是如果我通过故事板向单元格添加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];
}
}
要么发布您遇到的问题代码,要么回到正在使用该控件的人身上并向他寻求帮助。如果您在使用代码时遇到困难,并且看到它我们可以为您提供帮助,我们随时为您提供帮助。 – 2013-03-14 01:42:01
对不起。我添加了代码。 – cherbear 2013-03-14 02:20:41
您发布的代码非常好。它应该工作。文本字段的代码在哪里?您正在通过故事板添加它,但为了连接它并触发手势事件,它的代码在哪里? – 2013-03-14 02:31:44