Figure out UIBarButtonItem frame in window?

前端 未结 11 1920
臣服心动
臣服心动 2020-11-28 02:58

UIBarButtonItem does not extend UIView, so there is nothing like a frame property.

But is there any way I can get what is it\'s CGRec

11条回答
  •  醉酒成梦
    2020-11-28 03:12

    I was able to get Werner Altewischer's WEpopover to work by passing up the toolbar along with the
    UIBarButton: Mod is in WEPopoverController.m

    - (void)presentPopoverFromBarButtonItem:(UIBarButtonItem *)item toolBar:(UIToolbar *)toolBar
                   permittedArrowDirections:(UIPopoverArrowDirection)arrowDirections 
                                   animated:(BOOL)animated 
    {
        self.currentUIControl = nil;
        self.currentView = nil;
        self.currentBarButtonItem = item;
        self.currentArrowDirections = arrowDirections;
        self.currentToolBar = toolBar;
    
        UIView *v = [self keyView];
        UIButton *button = nil;
    
        for (UIView *subview in toolBar.subviews) 
        {
            if ([[subview class].description isEqualToString:@"UIToolbarButton"])
            {
                for (id target in [(UIButton *)subview allTargets]) 
                {
                    if (target == item) 
                    {
                        button = (UIButton *)subview;
                        break;
                    }
                }
                if (button != nil) break;
            }
        }
    
        CGRect rect = [button.superview convertRect:button.frame toView:v];
    
        [self presentPopoverFromRect:rect inView:v permittedArrowDirections:arrowDirections animated:animated];
    }
    

提交回复
热议问题