混合运动布局和茶杯

时间:2013-10-25 20:45:01

标签: autolayout rubymotion

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

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

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

(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视图的子视图。这是怎么回事?

1 个答案:

答案 0 :(得分:0)

在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块,然后对布局中的内容不会有任何歧义。

相关问题