你可以检查
containerView.subviews
属性确定每个子视图的Z位置。
数组开头的项比数组末尾的项深。
我相信这对您的测试是有效的,尽管我现在没有访问Xcode的权限来验证它是否正确。
- (void)testViewHierarchyFlipping {
STAssertEquals(containerView, shadowView.superview, nil);
STAssertEquals(containerView, contentView.superview, nil);
// Test that shadowView is ABOVE contentView.
UIView *topView = (UIView *)[[containerView subviews] lastObject];
UIView *bottomView = (UIView *)[[containerView subviews] objectAtIndex:0];
STAssertEquals(shadowView, topView, nil);
STAssertEquals(contentView, bottomView, nil);
}