自iOS 8以来,我遇到了一个问题,在自定义UITableViewCell上滑动删除手势。UITableViewCell里面的UITextField刷卡删除问题
该问题似乎来自UITableViewCell的contentView内的UITextField。
这似乎是在iOS的8个问题,我在iOS版7相同的代码工作正常
我如何能保持的UITextField编辑和滑动删除手势在同一时间工作?
自iOS 8以来,我遇到了一个问题,在自定义UITableViewCell上滑动删除手势。UITableViewCell里面的UITextField刷卡删除问题
该问题似乎来自UITableViewCell的contentView内的UITextField。
这似乎是在iOS的8个问题,我在iOS版7相同的代码工作正常
我如何能保持的UITextField编辑和滑动删除手势在同一时间工作?
以下为我工作:
self.tableView.panGestureRecognizer.delaysTouchesBegan = YES;
更容易我会尝试 – Yann86 2014-10-08 07:40:09
这工作,谢谢。 – 2014-10-08 09:05:00
我发现我的问题的解决方法中的iOS 8
子类的UITextField和上也是UITextField的顶部添加视图,则在“面具”视图中添加UIGestureRecognizer为单一的水龙头。
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
@interface OMTextField : UITextField
@property (nonatomic,retain) NSNumber*canBecomeFirstResponderFlag;
@end
@implementation OMTextField
-(id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) {
_canBecomeFirstResponderFlag = @0;
UIView*mask = [[UIView alloc] init];
mask.translatesAutoresizingMaskIntoConstraints = NO;
NSLayoutConstraint *maskT = [NSLayoutConstraint constraintWithItem:mask attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0];
NSLayoutConstraint *maskB = [NSLayoutConstraint constraintWithItem:mask attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0];
NSLayoutConstraint *maskL = [NSLayoutConstraint constraintWithItem:mask attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0.0];
NSLayoutConstraint *maskR = [NSLayoutConstraint constraintWithItem:mask attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1.0 constant:0.0];
[self addSubview:mask];
[self addConstraints:@[maskT,maskB,maskL,maskR]];
UITapGestureRecognizer *singleFingerTap =
[[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleSingleTap:)];
[mask addGestureRecognizer:singleFingerTap];
}
}
return self;
}
-(BOOL)canBecomeFirstResponder{
BOOL canBecomeFirstResponder;
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")) {
canBecomeFirstResponder = [_canBecomeFirstResponderFlag boolValue];
_canBecomeFirstResponderFlag = @0;
}
else{
canBecomeFirstResponder = [self.delegate textFieldShouldBeginEditing:self];
}
return canBecomeFirstResponder;
}
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {
_canBecomeFirstResponderFlag = @1;
BOOL souldBecomeFirstResponder = [self.delegate textFieldShouldBeginEditing:self];
if (souldBecomeFirstResponder) {
[self becomeFirstResponder];
}
}
@end
感谢您的分享。尽管我已经将赏金赏给了其他答案,因为实施起来要简单得多。 – 2014-10-08 09:05:33
一些测试后,我可以证实这确实是一个iOS 8的问题。这个问题不会发生在iOS 7上。 – 2014-10-07 12:06:15
如果你想我找到了解决方法。 – Yann86 2014-10-07 12:16:38
那太棒了! – 2014-10-07 12:17:13