gpt4 book ai didi

ios - UITextField block 在 UITableViewCell 内滚动

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:13:21 26 4
gpt4 key购买 nike

我在 UITableViewCells 中有 UITextFields。 TextView 似乎阻止了滚动。当我将指尖放在 TextView 的边界内并尝试滚动整个表格时,它不会滚动。在 TextView 之外可以滚动。

我怎样才能阻止这种行为?

最佳答案

下面的代码有点乱,但对我有用,基本上只需将 UITextView 上的 userInteractionEnabled 设置为 NO,然后在检测到用户点击它时设置为 YES。下面是我的带有 textview 的自定义单元格的代码,当用户从 UITextView 中启动滚动时,它对我来说滚动得很好。这是有效的,因为滚动是平移手势而不是点击。

#import "MyCell.h"

@interface MyCell () <UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UITextField *textField;

@end

@implementation MyCell

- (void)awakeFromNib
{
self.textField.userInteractionEnabled = NO;
self.textField.delegate = self;

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didTap:)];
[self addGestureRecognizer:tapRecognizer];
}

#pragma mark - Private methods

- (void)didTap:(UITapGestureRecognizer *)tapRecognizer
{
CGPoint location = [tapRecognizer locationInView:self];

CGRect pointRect = CGRectMake(location.x, location.y, 1.0f, 1.0f);
if (!CGRectIsNull(CGRectIntersection(pointRect, self.textField.frame))) {
self.textField.userInteractionEnabled = YES;
[self.textField becomeFirstResponder];
}
}

#pragma mark - UITextFieldDelegate methods

- (void)textFieldDidEndEditing:(UITextField *)textField
{
self.textField.userInteractionEnabled = NO;
}

@end

关于ios - UITextField block 在 UITableViewCell 内滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17151508/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com