以编程方式获取“Z” UIView 与其兄弟姐妹相比的位置
我的类具有在层次结构中的某些级别插入视图的逻辑。
containerView = [[UIView alloc] init];
shadowView = [[UIView alloc] init];
contentView = [[UIView alloc init];
[containerView addSubview:shadowView];
[containerView insertSubview:contentView belowSubview:shadowView];
随后,它会翻转它们,使阴影视图位于内容视图下方而不是上方。
// "Flipping" their positions.
[containerView insertSubview:contentView aboveSubview:shadowView];
UIView 有一个 subviews
属性返回 NSArray,不幸的是该数组不反映视图堆栈顺序。
我想对视图与其同级视图的位置进行比较。我该怎么做?
这是一个测试示例。
- (void)testViewHierarchyFlipping {
STAssertEquals(containerView, shadowView.superview, nil);
STAssertEquals(containerView, contentView.superview, nil);
// Test that shadowView is ABOVE contentView.
}
My class has logic for inserting views in certain levels in the hierarchy.
containerView = [[UIView alloc] init];
shadowView = [[UIView alloc] init];
contentView = [[UIView alloc init];
[containerView addSubview:shadowView];
[containerView insertSubview:contentView belowSubview:shadowView];
Later down the line, it flips them so the shadow view is below the content view instead of above it.
// "Flipping" their positions.
[containerView insertSubview:contentView aboveSubview:shadowView];
UIView has a subviews
property returning an NSArray, unfortunately the array does not reflect the view stack ordering.
I want to unit test the placement of the view compared to it's siblings. How can I do that?
Here's an example of a test.
- (void)testViewHierarchyFlipping {
STAssertEquals(containerView, shadowView.superview, nil);
STAssertEquals(containerView, contentView.superview, nil);
// Test that shadowView is ABOVE contentView.
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以检查
containerView.subviews
属性来确定每个子视图的 Z 位置。数组开头的项目比数组末尾的项目更深。
我相信这应该适用于您的测试,尽管我目前无法访问 Xcode 来验证它是否正确。
You can inspect the
containerView.subviews
property to determine the Z position of each subview.Items at the beginning of the array are deeper than items at the end of the array.
I believe this should work for your test, although I don't have access to Xcode to verify that it's correct at the moment.