可以使用以下代码将 view b 放到 view c 后面:\n\nswift\n// 将 view b 从父视图中移除\nviewB.removeFromSuperview()\n\n// 将 view b 添加到 view c 后面\nviewC.addSubview(viewB)\n\n如果你想要将 view b 放到 view c 的后面,而不是作为其子视图,可以使用以下代码:\n\nswift\n// 获取 view c 的父视图\nguard let superview = viewC.superview else {\n return\n}\n\n// 获取 view c 的索引\nlet index = superview.subviews.firstIndex(of: viewC)\n\n// 将 view b 插入到 view c 的后面\nsuperview.insertSubview(viewB, at: index!+1)\n\n\n这样,view b 就会被放到 view c 的后面。'}


原文地址: https://www.cveoy.top/t/topic/mkRk 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录