我已經在我的項目中實現了此自定義控件: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