UITextView长按弹出UIMenuController问题

 iOS 上线应用被拒 反馈如下:

Dear developer,

We have discovered one or more issues with your recent delivery for "紫色医疗医生版-医师执业助手第一平台.电话答题随诊访病历夹". To process your delivery, the following issues must be corrected:

Non-public API usage:

The app references non-public selectors in *****: _define:, _promptForReplace:, _share:, _transliterateChinese:

If method names in your source code match the private Apple APIs listed above, altering your method names will help prevent this app from being flagged in future submissions. In addition, note that one or more of the above APIs may be located in a static library that was included with your app. If so, they must be removed.

If you think this message was sent in error and that you have only used Apple-published APIs in accordance with the guidelines, send the app's nine-digit Apple ID, along with detailed information about why you believe the above APIs were incorrectly flagged, [email protected]. For further information, visit theTechnical Support Informationpage.

Once these issues have been corrected, you can then redeliver the corrected binary.

Regards,

The App Store team

大概意思就是我们用了 苹果的私有 api  _define:, _promptForReplace:, _share:, _transliterateChinese:的方法

列举选择项

cut:  copy:  select:  selectAll:  paste:  delete:  _promptForReplace:  _transliterateChinese:  _showTextStyleOptions:  _define:  _addShortcut:  _accessibilitySpeak:  _accessibilitySpeakLanguageSelection:  _accessibilityPauseSpeaking:  makeTextWritingDirectionRightToLeft: makeTextWritingDirectionLeftToRight:

其中下边这些是可以访问的公开方法

- (void)cut:(nullableid)senderNS_AVAILABLE_IOS(3_0);

- (void)copy:(nullableid)senderNS_AVAILABLE_IOS(3_0);

- (void)paste:(nullableid)senderNS_AVAILABLE_IOS(3_0);

- (void)select:(nullableid)senderNS_AVAILABLE_IOS(3_0);

- (void)selectAll:(nullableid)senderNS_AVAILABLE_IOS(3_0);

- (void)delete:(nullableid)senderNS_AVAILABLE_IOS(3_2);

- (void)makeTextWritingDirectionLeftToRight:(nullableid)senderNS_AVAILABLE_IOS(5_0);

- (void)makeTextWritingDirectionRightToLeft:(nullableid)senderNS_AVAILABLE_IOS(5_0);


现在有个需求如下图:添加一个"添加为模版"

UITextView长按弹出UIMenuController问题_第1张图片

第一种代码  

代码如下:自定义了一个PHTTextView 继承UITextView 中加入一下代码

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender

{

if(action ==@selector(copy:) ||

action ==@selector(selectAll:)||

action ==@selector(cut:)||

action ==@selector(select:)||

action ==@selector(paste:)) {

return[supercanPerformAction:actionwithSender:sender];//

}

returnNO;

}


在使用PHTTextView的controller中添加如下代码

UIMenuItem*menuItem = [[UIMenuItemalloc]initWithTitle:@"添加为模板"action:@selector(addToTemplate:)];

UIMenuController*menu = [UIMenuControllersharedMenuController];

[menusetMenuItems:[NSArrayarrayWithObjects:menuItem,nil]];

实现效果上图那样. 点击"全选"之后   全选按钮 就没有了 


UITextView长按弹出UIMenuController问题_第2张图片

第二种代码

如果把代码改成 如下 

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender

{

if(action ==@selector(copy:) ||

action ==@selector(selectAll:)||

action ==@selector(cut:)||

action ==@selector(select:)||

action ==@selector(paste:)) {

returnYES; *--让满足条件的  都显示出来--*

}

returnNO;

}


UITextView长按弹出UIMenuController问题_第3张图片

点击全选之后  效果如下

其实这时候 就能 看出来 apple 的这个方式是给我们优化的  [super canPerformAction:action withSender:sender]; 因为没有全部选择之前 进行"剪切""拷贝"是没有任何意义的.

如果固定 全部写成 YES 他会把你所有 想要的展示出来.

第三种代码 

把 PHTTextView 中的 -(BOOL)canPerformAction:(SEL)action withSender:(id)sender方法改为第一种代码

让后在viewcontroller中添加了 如下 代码

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender

{

if(action ==@selector(addToTemplate:)) {//添加为模板方法

if(self.contentView.selectedRange.length>0) {

returnYES;

}else{

returnNO;

}

return[supercanPerformAction:actionwithSender:sender];

}

效果如下

UITextView长按弹出UIMenuController问题_第4张图片

点击"全选"或者"选择"之后 才会出来 "添加为模板" 是因为 这句话 if(self.contentView.selectedRange.length>0) {returnYES;}else{returnNO;} 如果textview 又被选择的文字 才会 返回 yes 否则no 

UITextView长按弹出UIMenuController问题_第5张图片

第四种代码

把PHTTextView中的-(BOOL)canPerformAction:(SEL)action withSender:(id)sender 方法全部注释

并且修改ViewController 方法 -(BOOL)canPerformAction:(SEL)action withSender:(id)sender

-(BOOL)canPerformAction:(SEL)action withSender:(id)sender

{

if(action ==@selector(addToTemplate:)) {//添加为模板方法

      if(self.contentView.selectedRange.length>0) {

          returnYES;

     }else{

         returnNO;

     }

}elseif(action ==@selector(copy:) ||

action ==@selector(selectAll:)||

action ==@selector(cut:)||

action ==@selector(select:)

){

    BOOLisAppear = [super canPerformAction:actionwithSender:sender];

    return isAppear;

}

//BOOLisAppear = [super canPerformAction:actionwithSender:sender];

return NO;

}

效果如下



点击"全选"

UITextView长按弹出UIMenuController问题_第6张图片

会出来很多不想要的事件  我也不知道为什么........... 求解


建议使用第一种和第三种  第三种 是优化 

你可能感兴趣的:(UITextView长按弹出UIMenuController问题)