Tag: uiview hierarchy

将子视图的X置于自动布局中将引发“未准备好约束”

我有一个自定义的UIView子类正在通过一个笔尖初始化。 在-awakeFromNib ,我创build了一个子视图,并尝试将它置于其超视图中。 [self setInteralView: [[UIView alloc] init]]; [[self internalView] addConstraint: [NSLayoutConstraint constraintWithItem: [self internalView] attribute: NSLayoutAttributeCenterX relatedBy: NSLayoutRelationEqual toItem: self attribute: NSLayoutAttributeCenterX multiplier: 1 constant: 0]]; 这打破了,并导致以下输出: 2013-08-11 17:58:29.628 MyApp[32414:a0b] The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0xc1dcc80 UIView:0xc132a40.centerX == MyView:0xc1315a0.centerX> When added to a view, the constraint's items must be descendants […]

使用hitTest:withEvent捕获超级视图框架外部的子视图:

我的问题:我有一个基本上占用了整个应用程序框架的一个EditView视图EditView和一个子视图MenuView ,它只占用底部ButtonView %,然后MenuView包含它自己的子视图ButtonView ,它实际上驻留在MenuView的界限之外像这样: ButtonView.frame.origin.y = -100 )。 (注意: EditView有其他的子视图不是MenuView的视图层次结构的一部分,但可能会影响答案。) 你可能已经知道这个问题了:当ButtonView在MenuView的范围内(或者更确切地说,当我的触摸在MenuView的范围内时), ButtonView响应触摸事件。 当我的触摸在MenuView的边界之外(但仍在ButtonView的边界内)时, ButtonView没有接收到触摸事件。 例: (E)是EditView ,它是所有视图的父视图 (M)是MenuView ,EditView的子视图 (B)是ButtonView ,MenuView的子视图 图: +——————————+ |E | | | | | | | | | |+—–+ | ||B | | |+—–+ | |+—————————-+| ||M || || || |+—————————-+| +——————————+ 因为(B)在(M)的框外,所以(B)区域的抽头将不会被发送到(M) – 实际上,(M)在这种情况下从不分析触摸,触摸被发送到层次结构中的下一个对象。 目标:我收集的压倒性hitTest:withEvent:可以解决这个问题,但我不明白如何。 在我的情况,应该hitTest:withEvent:在EditView (我的'主'超视图)重写? 或者应该在MenuView中重写,没有接收的button的直接超视图接触? 还是我错误地想这个? […]