【问题标题】:Cannot select/edit text in UITextView within UIScrollView无法在 UIScrollView 内的 UITextView 中选择/编辑文本
【发布时间】:2015-11-17 17:04:38
【问题描述】:

我已经使用 Masonry 设置了我的 UIScrollView 和子视图:

- (void)setupViews {
    self.view.backgroundColor = [UIColor Background];
    self.scrollView = [UIScrollView new];
    self.scrollView.alwaysBounceVertical = YES;
    [self.view addSubview:self.scrollView];
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    self.contentView = [UIView new];
    [self.scrollView addSubview:self.contentView];
    self.scrollView.backgroundColor = [UIColor clearColor];
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.scrollView);
        make.left.and.right.equalTo(self.view);
    }];
    self.imageButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.imageButton sd_setImageWithURL:[NSURL URLWithString:self.card.cardImageURL] forState:UIControlStateNormal];
    [self.imageButton.imageView setContentMode:UIViewContentModeScaleAspectFill];
    [self.contentView addSubview:self.imageButton];
    [self.imageButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.and.right.equalTo(self.contentView);
        make.height.equalTo(self.imageButton.mas_width).multipliedBy(3/4.0);
    }];
    self.textField = [UITextField new];
    self.textField.backgroundColor = [UIColor whiteColor];
    self.textField.font = kFontRegular(14);
    self.textField.text = self.card.cardTitle;
    [self.contentView addSubview:self.textField];
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).with.offset(8);
        make.top.equalTo(self.imageButton.mas_bottom).with.offset(8);
        make.right.equalTo(self.contentView).with.offset(-8);
        make.height.equalTo(@(45));
    }];
}

但它不会让我与 UITextField 交互。这里有什么元素阻止用户交互?

【问题讨论】:

  • 您是否尝试设置启用、可编辑、...?
  • 是的,默认情况下 UITextField 应该是可编辑的
  • 你可以尝试使用背景来确定约束没问题吗?
  • 我担心 UITextField 的框架。不确定。我和你一样不知道原因。
  • 那些行不是必需的 - 我已经在上面编辑了我的代码。它仍然是不可交互的

标签: ios objective-c uiscrollview uitextfield masonry


【解决方案1】:

您的 contentView 的高度将为零。所以它永远不会得到一些触摸事件。你不应该使用这个约束:

make.edges.equalTo(self.scrollView);

它不会得到正确的值。尝试为您的 contentView 设置顶部和高度限制。

make.top.equalTo(@0);
make.height.equalTo(@700);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-19
    • 2012-11-06
    相关资源
    最近更新 更多