Adding Speech to custom UIMenuController

后端 未结 2 2187
陌清茗
陌清茗 2021-02-15 12:33

I created a custom UIMenuController in a UIWebView but it seems to get rid of the \"Speak Selection\" option in the UIMenuController after

2条回答
  •  北荒
    北荒 (楼主)
    2021-02-15 13:27

    I've found some interesting things with this bug. Basically, when speak selection is enabled, after you make the first selection the UIMenuController is emptied of menuItems. The solution, though hacky, is simple.

    - (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    NSString *selectorString = NSStringFromSelector(action);
    BOOL isAccessibilitySelector = [selectorString isEqualToString:@"_accessibilitySpeak:"] || [selectorString isEqualToString:@"_accessibilityPauseSpeaking:"];
    if (isAccessibilitySelector && [super canPerformAction:action withSender:sender]) {
        //(re)add menuItems to UIMenuController
        return YES;
    }
    return NO;
    

    }

    I should note that you must re-add the menuItems after their canPerformAction...() has been called.

    I have submitted this as radar:12931434. Update: DUP'ed to 13060693.

提交回复
热议问题