【问题标题】:Mixing motion-layout and Teacup混合运动布局和茶杯
【发布时间】:2013-10-25 20:45:01
【问题描述】:

我正在尝试在 RubyMotion 项目中混合运动布局和茶杯。我创建了一个示例视图助手来说明我的问题:

module Teacup::Layout

  def example(name, options = {})

    subview UIView, name do
      subview UILabel, "#{name}_label".to_sym, text: options[:label]

      auto do
        horizontal "|-[#{name}_label]-|"
      end
    end
  end
end

当我在 layout 块内调用 example(:example), text: "Test" 时,我的代码会引发以下异常:

(main)> 2013-10-25 13:40:45.989 rui[55552:80b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse constraint format:
example_label is not a key in the views dictionary.
H:|-[example_label]-|

如果我省略运动布局代码并检查视图,example_label 视图是 example 视图的子视图。这是怎么回事?

【问题讨论】:

  • 也许尝试使用字符串而不是符号?我不是自动布局专家。
  • 不幸的是,这并没有成功。
  • 我认为这段代码应该可以工作,明天我会玩它! :-)

标签: autolayout rubymotion


【解决方案1】:

在 Teacup 的文档中,它说:

# if you need to apply these to a different view, or if you want to assign
# different names to use in the ASCII strings
# auto(layout_view=self.view, layout_subviews={}, &layout_block)

由于创建所有这些视图的“动态”性质,并且布局(运动布局)位于子视图而不是布局(茶杯)中,它可能会让人感到困惑,尽管子视图和布局是类似。

无论如何,请尝试使用文档中的建议非常具体地确定哪些视图将进入 auto 块,这样布局中的内容就不会有歧义了。

【讨论】:

    猜你喜欢
    • 2013-06-17
    • 1970-01-01
    • 2022-11-25
    • 2017-02-02
    • 1970-01-01
    • 1970-01-01
    • 2019-07-24
    • 1970-01-01
    • 2014-06-04
    相关资源
    最近更新 更多