ULPriorityView 0.0.3

ULPriorityView 0.0.3

测试测试
语言语言 Obj-CObjective C
许可证 MIT
发布最新发布2017年1月

upworldcjw 维护。



  • upowrld

这可以帮助您按照优先级组织子视图。
继承自 ULPriorityView 的视图实例在最顶层的 most priorityLevel。
可以设置视图的优先级,优先级越高越靠上。(考上是指在(view.subViews中的index值))
//如果priorityLevel设置值相等,则谁后加到view上谁靠上。(和普通view特性一致)

  • (void)testSameLevel{
    UIView *subView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    subView1.priorityLevel = 1;
    subView1.backgroundColor = [UIColor redColor];
    [view addSubview:subView1];

    UIView *subView2 = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 30, 30)];
    subView2.priorityLevel = 1;
    subView2.backgroundColor = [UIColor blueColor];
    [view addSubview:subView2];

    //此时subView1的index = 0,subView2的index = 1

    [view bringSubviewToFront:subView1];

    //此时subview1的index = 1,subview2的index = 0
    }

//如果priorityLevel设置值不相等,值越大越靠上(不管谁先加到view上)。

  • (void)testDiffentLevel{
    UIView *subView2 = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 30, 30)];
    subView2.priorityLevel = 2;
    subView2.backgroundColor = [UIColor blueColor];
    [view addSubview:subView2];

    UIView *subView1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    subView1.priorityLevel = 1;
    subView1.backgroundColor = [UIColor redColor];
    [view addSubview:subView1];

    //此时subview1的index = 0,subView2的index = 1。尽管subview2先addsubView

    [view bringSubviewToFront:subView1];

    //但由于subView2的priorityLevel较大,所以调用这个方法后subView1的index仍然为0,subview2的index还是1。尽管subview2先addsubView.
    //bringSubviewToFront,sendsubviewToBack只针对相同的priorityLevel调用有效

}