新建一个类继承UITextField,然后实现canPerformAction方法:
.h
import <UIKit/UIKit.h>
@interface NoCopyTextField : UITextField
@end
.m
import "NoCopyTextField.h"
@implementation NoCopyTextField
-
(id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
} -
(BOOL)canPerformAction:(SEL)action withSender:(id)sender {
UIMenuController *menuController = [UIMenuController sharedMenuController];
if (menuController) {
[UIMenuController sharedMenuController].menuVisible = NO;
}
return NO;
}
用hook机制对canPerformAction 检测就好了, 很简单
网友评论