UIMenuController為啥不顯示呢

首先就是創(chuàng)建

- (void)deleteBtnAction:(UIButton *)deleteBtn
{
    [self becomeFirstResponder];// 用于UIMenuController顯示,缺一不可
    UIMenuController *menu = [UIMenuController sharedMenuController];
    UIMenuItem *item1 = [[UIMenuItem alloc] initWithTitle:@"撤銷" action:@selector(revokeAction)];
    UIMenuItem *item2 = [[UIMenuItem alloc] initWithTitle:@"確認(rèn)" action:@selector(sureAction)];
    menu.menuItems = @[item1, item2];
    menu.arrowDirection = UIMenuControllerArrowUp;
    [menu setTargetRect:deleteBtn.frame inView:deleteBtn.superview];//  [menu setTargetRect:所點(diǎn)擊的按鈕Frame inView:按鈕的父視圖];
    [menu setMenuVisible:YES animated:YES];
}

用于UIMenuController顯示,不可缺少的方法

-(BOOL)canBecomeFirstResponder{
    
    return YES;
 }
-(BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
    if (action == @selector(revokeAction)) {
        return YES;
    }
    if (action == @selector(sureAction)) {
        return YES;
    }
    return NO;//隱藏系統(tǒng)默認(rèn)的菜單項(xiàng)
}

我們可以獲取UIMenuController的通知,從而做出相應(yīng)的操作

//UIMenuControllerWillShowMenuNotification == 將要顯示
//UIMenuControllerDidShowMenuNotification  === 已經(jīng)顯示
//UIMenuControllerWillHideMenuNotification  == 將要隱藏
//UIMenuControllerDidHideMenuNotification == 已經(jīng)隱藏
//UIMenuControllerMenuFrameDidChangeNotification  == 位置大小改變


 //UIMenuController已經(jīng)隱藏的通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(menuControllerDidHide) name:UIMenuControllerDidHideMenuNotification object:nil];
//通知回調(diào)的方法
- (void)menuControllerDidHide
{
//可以做相應(yīng)的操作

}

效果圖如下

11)效果圖.jpg
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,586評(píng)論 19 139
  • 點(diǎn)擊查看原文 Web SDK 開發(fā)手冊 SDK 概述 網(wǎng)易云信 SDK 為 Web 應(yīng)用提供一個(gè)完善的 IM 系統(tǒng)...
    layjoy閱讀 14,315評(píng)論 0 15
  • “長夜深深深何許?自爾東西南北中。” 我知,你我自一別后,再無錯(cuò)眼可能,連錯(cuò)眼亦再無可能。 2017年7月23日 ...
    仍未忘與你約定閱讀 726評(píng)論 6 2
  • 獨(dú)倚高樓望天際,混天夜里,惟聞?dòng)曷暵涞?。杯酒入腸觸情起,不語誰會(huì)憑闌意。擬把霖雨作玉具①,斬?cái)喾矇m,強(qiáng)樂還無趣。青...
    元鷙閱讀 329評(píng)論 0 2
  • 清晨,走向去學(xué)校的小路上,抬頭望望天空還是一派朦朧的景象,一棵棵白楊樹直插云霄,太陽從東方慢慢升起,紅中透紫,紫中...
    陳嘉慶620閱讀 280評(píng)論 0 0

友情鏈接更多精彩內(nèi)容