zoukankan      html  css  js  c++  java
  • UIBarButtonItem不能获取frame

    在使用KxMenu这个厉害的控件做竖直列表的时候,发现UIBarButtonItem不能获取到frame,UIBarButtonItem是NSObject的子类,他不是一个uiresponed或者uiview的子类,所以他没有frame属性.

    所以当我们要确定弹出框的位置的时候,

    UIBarButtonItem *addContactItem = [[UIBarButtonItem alloc] initWithTitle:@"添加"
                                                                       style:UIBarButtonItemStylePlain
                                                                      target:self action:@selector(addContact:event:)];
    

     在设置action selector的时候多传递一个event参数,然后:

    - (void)addContact:(UIBarButtonItem *)sender event:(UIEvent *) event {
         NSArray *menuItems = @[
                             [KxMenuItem menuItem:@"添加朋友" image:nil target:self action:@selector(addFriend)],
                             [KxMenuItem menuItem:@"添加群组" image:nil target:self action:@selector(addGroup)],
                             [KxMenuItem menuItem:@"添加班级" image:nil target:self action:@selector(addClass)],
                             [KxMenuItem menuItem:@"扫一扫" image:nil target:self action:@selector(scan)]
                             ];
    
        CGRect fromRect = [[event.allTouches anyObject] view].frame;
    
        fromRect.origin.y += 20;
    
        [KxMenu showMenuInView:self.view.window
                      fromRect:fromRect
                     menuItems:menuItems];
    }
    

    这样我们就可以定位到触发动作的uibarbuttonitem的位置,并正确弹出窗口。

  • 相关阅读:
    UML用例图
    Google Map API 文档
    chrome 使用各种搜索引擎的方法 GIS
    javaScript 获得触发事件的元素 支持IE FireFox GIS
    html 的路径 GIS
    JavaScript prototype GIS
    chromium 的资源管理 的grit GIS
    [原]使用ucenter最土团购整合DX2bbs的心得
    [转]sqlserver日期函数
    最土Ajax实现/json
  • 原文地址:https://www.cnblogs.com/ritian/p/6222945.html
Copyright © 2011-2022 走看看