在UITextview
中按下触摸更长时间放大镜出现时。我怎样才能禁用它。
答案 0 :(得分:30)
最后这个问题也解决了
以下是任何人需要的参考代码
在子文件UITextview的m文件中添加了代码
-(void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
{
//Prevent zooming but not panning
if ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]])
{
gestureRecognizer.enabled = NO;
}
[super addGestureRecognizer:gestureRecognizer];
return;
}
有效。
答案 1 :(得分:1)
这对我有用
@implementation CustomTextView
- (NSArray *)selectionRectsForRange:(UITextRange *)range
{
self.selectedTextRange = nil;
return nil;
}
- (void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
{
gestureRecognizer.delegate = self;
[super addGestureRecognizer:gestureRecognizer];
return;
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
return NO;
}
- (CGRect)caretRectForPosition:(UITextPosition *)position
{
return [super caretRectForPosition:self.endOfDocument];
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if (([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]] && !gestureRecognizer.delaysTouchesEnded))
{
return NO;
}
else
return YES;
}
答案 2 :(得分:0)
Xamarin.iOS:
requireAuth
上覆盖function requireAuth(allowProxyLogin) {
return [
(req, res, next) => {
req.allowProxyLogin = !!allowProxyLogin;
return next();
},
passport.authenticate('jwt', { session: false, passReqToCallback: true }),
];
}
方法GestureRecognizerShouldBegin
答案 3 :(得分:-1)
@Irina的答案部分工作(尝试轻按,然后长按,你将有一个放大叠加),适用于iOS 9.x,并在iOS 10上崩溃,具体如下:
***由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:'您无法更改委托 UIViewControllerPreviewing失败关系手势 识别器“
以下代码适用于iOS 9.x和10.x,我能想到的每个轻拍和/或长手势组合。
注意我不保证Apple的评论会接受。
@implementation CustomTextView
- (void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
{
NSArray *allowedGestures = @[ @"UILongPressGestureRecognizer", @"UIScrollViewDelayedTouchesBeganGestureRecognizer", @"UIScrollViewPanGestureRecognizer" ];
if (![allowedGestures containsObject:NSStringFromClass([gestureRecognizer class])])
{
return;
}
if (([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]] && !gestureRecognizer.delaysTouchesEnded))
{
return;
}
[super addGestureRecognizer:gestureRecognizer];
}
@end
我们需要UIScrollViewDelayedTouchesBeganGestureRecognizer
和UIScrollViewPanGestureRecognizer
才能保持UITextView
滚动功能。这两个类都是私有API 的一部分,因此请自行承担风险。
答案 4 :(得分:-1)
@ user1120133的答案的Swift 4版本:
override func addGestureRecognizer(_ gestureRecognizer: UIGestureRecognizer) {
//Prevent long press to show the magnifying glass
if gestureRecognizer is UILongPressGestureRecognizer {
gestureRecognizer.isEnabled = false
}
super.addGestureRecognizer(gestureRecognizer)
}