如何找到特定UITabBarItem的UIView? [英] How can I find the UIView for a specific UITabBarItem?

查看:71
本文介绍了如何找到特定UITabBarItem的UIView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个名为SwiftyWalkthrough的外部库,该库使我只能在屏幕上公开某些视图,以通过应用程序的UI引导新用户.我要向用户显示的第一项是UITabBarItem.我需要找到与该特定UITabBarItem关联的UIView.我知道该项目的索引,并且给了它一个标签.但是我还没有找到一种方法来帮助他们找到视图.当然,我只想使用公共接口来完成此任务.

I am using an external library called SwiftyWalkthrough, which allows me to expose only certain views on the screen to guide a new user through my app's UI. The first item I want exposed to the user is a UITabBarItem. I need to find the UIView associated with that specific UITabBarItem. I know the index for the item, and I have given it a tag. But I haven't found a way for them to help me find the view. Of course, I only want to use public interfaces to accomplish this.

推荐答案

我通过访问tabBar的子视图解决了我的问题.具有userInteractionEnabled的视图是UITabBarItems.按照它们的minX值对它们进行排序,可以确保它们与tabBar.items数组的顺序相同.

I solved my problem by accessing the subviews of the tabBar. The views with userInteractionEnabled are UITabBarItems. Sorting them by their minX values guarantees that they are in the same order as the tabBar.items array.

extension UITabBarController {
    func orderedTabBarItemViews() -> [UIView] {
        let interactionViews = tabBar.subviews.filter({$0.isUserInteractionEnabled})
    return interactionViews.sorted(by: {$0.frame.minX < $1.frame.minX})
    }
}

这篇关于如何找到特定UITabBarItem的UIView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆