简体   繁体   中英

Finding the location of a UITabBarItem in Monotouch Xamarin.iOS

Im trying to implement my own popup menu from a UITabBar. My app allows users to specify which menus are displayed on the tab bar and I'm not keen on the default "More" button that iOS uses when there are a lot of tab bar items so I would like to create some of the tab bar items to be "Sub menus" that pup up a menu of further buttons. I would like it to pop up from the tabbaritem itself and the order of the tabs may not be the same for every user. So far I can find the tabbaritem the user has selected but next i need to know its location so I can animate a popup menu from that location.

Does anyone know how I could go about finding the frame or position of the selected tabbaritem?

You can iterate trough the subviews of your UITabBar and get only those subviews which are a type of UITabBarButton class. Then you get the frame of the subviews you are interested in.

List<RectangleF> tabBarButtonFrames = new List<RectangleF>();

foreach (var view in this.tabBarController.TabBar.Subviews) {
    if (view.ToString().Contains("UITabBarButton")) {
        tabBarButtonFrames.Add(view.Frame);
    }

    Console.WriteLine(view.ToString() + "\t" + view.Frame.ToString());
}

Note: This link contains more ways of getting the Objective-C class names from poupou

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM