1. <small id='6Y3i8'></small><noframes id='6Y3i8'>

      <i id='6Y3i8'><tr id='6Y3i8'><dt id='6Y3i8'><q id='6Y3i8'><span id='6Y3i8'><b id='6Y3i8'><form id='6Y3i8'><ins id='6Y3i8'></ins><ul id='6Y3i8'></ul><sub id='6Y3i8'></sub></form><legend id='6Y3i8'></legend><bdo id='6Y3i8'><pre id='6Y3i8'><center id='6Y3i8'></center></pre></bdo></b><th id='6Y3i8'></th></span></q></dt></tr></i><div id='6Y3i8'><tfoot id='6Y3i8'></tfoot><dl id='6Y3i8'><fieldset id='6Y3i8'></fieldset></dl></div>
    2. <legend id='6Y3i8'><style id='6Y3i8'><dir id='6Y3i8'><q id='6Y3i8'></q></dir></style></legend>

      • <bdo id='6Y3i8'></bdo><ul id='6Y3i8'></ul>
      <tfoot id='6Y3i8'></tfoot>

      UIBarButtonItem 与 UIButton 作为 CustomView - 从 UIButton,如何访问它的

      UIBarButtonItem with UIButton as CustomView - from UIButton, how to access the UIBarButtonItem its in?(UIBarButtonItem 与 UIButton 作为 CustomView - 从 UIButton,如何访问它的 UIBarButtonItem?)
        <tbody id='L68Tf'></tbody>

          <i id='L68Tf'><tr id='L68Tf'><dt id='L68Tf'><q id='L68Tf'><span id='L68Tf'><b id='L68Tf'><form id='L68Tf'><ins id='L68Tf'></ins><ul id='L68Tf'></ul><sub id='L68Tf'></sub></form><legend id='L68Tf'></legend><bdo id='L68Tf'><pre id='L68Tf'><center id='L68Tf'></center></pre></bdo></b><th id='L68Tf'></th></span></q></dt></tr></i><div id='L68Tf'><tfoot id='L68Tf'></tfoot><dl id='L68Tf'><fieldset id='L68Tf'></fieldset></dl></div>

          <tfoot id='L68Tf'></tfoot>

          <small id='L68Tf'></small><noframes id='L68Tf'>

          • <legend id='L68Tf'><style id='L68Tf'><dir id='L68Tf'><q id='L68Tf'></q></dir></style></legend>

              • <bdo id='L68Tf'></bdo><ul id='L68Tf'></ul>

                本文介绍了UIBarButtonItem 与 UIButton 作为 CustomView - 从 UIButton,如何访问它的 UIBarButtonItem?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个 UIBarButtonItemUIButton 作为自定义视图.

                I have a UIBarButtonItem with UIButton as custom view.

                UIButton 上有一个 addTarget:action:.在动作中,我展示了一个弹出框.我目前正在从 sender.frame(UIButton 的框架)呈现我想从 UIBarButtonItem 呈现.

                The UIButton has a addTarget:action: on it. In the action I present a popover. I'm currently presenting from the sender.frame (the UIButton's Frame) I want to Present from the UIBarButtonItem instead.

                如何从 UIButton 访问 UIBarButtonItem?

                推荐答案

                如果您已将 UIButton 设置为 UIBarButtonItemcustomView,或者自定义视图的子视图,然后您可以从按钮向上遍历视图层次结构,直到找到包含该按钮的 UIToolbarUINavigationBar,然后搜索栏的其自定义视图是按钮(或按钮的祖先)的项目.

                If you have set your UIButton as the customView of a UIBarButtonItem, or a child of the custom view, then you can walk up the view hierarchy from your button until you find the UIToolbar or UINavigationBar that contains the button, then search the bar's items for the one whose custom view is the button (or an ancestor of the button).

                这是我完全未经测试的代码.您将调用 [[self class] barButtonItemForView:myButton] 来获取包含您的按钮的项目.

                Here's my completely untested code for doing that. You would call [[self class] barButtonItemForView:myButton] to get the item containing your button.

                + (BOOL)ifBarButtonItem:(UIBarButtonItem *)item containsView:(UIView *)view storeItem:(UIBarButtonItem **)outItem {
                    UIView *customView = item.customView;
                    if (customView && [view isDescendantOfView:customView]) {
                        *outItem = item;
                        return YES;
                    } else {
                        return NO;
                    }
                }
                
                + (BOOL)searchBarButtonItems:(NSArray *)items forView:(UIView *)view storeItem:(UIBarButtonItem **)outItem {
                    for (UIBarButtonItem *item in items) {
                        if ([self ifBarButtonItem:item containsView:view storeItem:outItem])
                            return YES;
                    }
                    return NO;
                }
                
                + (UIBarButtonItem *)barButtonItemForView:(UIView *)view {
                    id bar = view;
                    while (bar && !([bar isKindOfClass:[UIToolbar class]] || [bar isKindOfClass:[UINavigationBar class]])) {
                        bar = [bar superview];
                    }
                    if (!bar)
                        return nil;
                
                    UIBarButtonItem *item = nil;
                
                    if ([bar isKindOfClass:[UIToolbar class]]) {
                        [self searchBarButtonItems:[bar items] forView:view storeItem:&item];
                    }
                
                    else {
                        UINavigationItem *navItem = [bar topItem];
                        if (!navItem)
                            return nil;
                        [self ifBarButtonItem:navItem.backBarButtonItem containsView:view storeItem:&item]
                        || [self ifBarButtonItem:navItem.leftBarButtonItem containsView:view storeItem:&item]
                        || [self ifBarButtonItem:navItem.rightBarButtonItem containsView:view storeItem:&item]
                        || ([navItem respondsToSelector:@selector(leftBarButtonItems)]
                            && [self searchBarButtonItems:[(id)navItem leftBarButtonItems] forView:view storeItem:&item])
                        || ([navItem respondsToSelector:@selector(rightBarButtonItems)]
                            && [self searchBarButtonItems:[(id)navItem rightBarButtonItems] forView:view storeItem:&item]);
                    }
                
                    return item;
                }
                

                这篇关于UIBarButtonItem 与 UIButton 作为 CustomView - 从 UIButton,如何访问它的 UIBarButtonItem?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                UIButton title text color(UIButton 标题文本颜色)
                Stretch background image for UIButton(为 UIButton 拉伸背景图像)
                Using Tint color on UIImageView(在 UIImageView 上使用 Tint 颜色)
                How can I change UIButton title color?(如何更改 UIButton 标题颜色?)
                iPhone UIButton - image position(iPhone UIButton - 图像位置)
                UIButton remove all target-actions(UIButton 删除所有目标动作)
                      <tbody id='TJaTS'></tbody>
                    <legend id='TJaTS'><style id='TJaTS'><dir id='TJaTS'><q id='TJaTS'></q></dir></style></legend>
                    • <bdo id='TJaTS'></bdo><ul id='TJaTS'></ul>
                      • <tfoot id='TJaTS'></tfoot>

                        <small id='TJaTS'></small><noframes id='TJaTS'>

                          <i id='TJaTS'><tr id='TJaTS'><dt id='TJaTS'><q id='TJaTS'><span id='TJaTS'><b id='TJaTS'><form id='TJaTS'><ins id='TJaTS'></ins><ul id='TJaTS'></ul><sub id='TJaTS'></sub></form><legend id='TJaTS'></legend><bdo id='TJaTS'><pre id='TJaTS'><center id='TJaTS'></center></pre></bdo></b><th id='TJaTS'></th></span></q></dt></tr></i><div id='TJaTS'><tfoot id='TJaTS'></tfoot><dl id='TJaTS'><fieldset id='TJaTS'></fieldset></dl></div>