我正在尝试在uiscrollview上取消滚动,如果它来自手写笔(苹果铅笔(。
有任何建议?
您可以在uigesturerecognizer上设置 allowedTouchTypes
属性。
例如:
scrollView.panGestureRecognizer.allowedTouchTypes = [UITouchType.direct.rawValue as NSNumber]
您可以找出触摸是否来自Fingure Usinng Uitouch的类型。
if (touch.type == UITouchTypeStylus) {
//its touch from Stylus.
}
现在,对于ScrollView,您可以创建UISCrollView的子类并实现TouchBegan方法
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
if (touch.type == UITouchTypeStylus) {
self.scrollEnabled = NO;
}
else
{
self.scrollEnabled = YES;
}
[super touchesBegan:touches withEvent:event];
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
if (touch.type == UITouchTypeStylus) {
self.scrollEnabled = NO;
}
else
{
self.scrollEnabled = YES;
}
[super touchesMoved:touches withEvent:event];
}
//编辑或
子类uiapplication:
@interface MyUIApplication : UIApplication
- (void)sendEvent:(UIEvent *)event {
[super sendEvent:event];
NSSet *allTouches = [event allTouches];
if ([allTouches count] > 0) {
/
UITouchPhase phase = ((UITouch *)[allTouches anyObject]).phase;
if (phase == UITouchPhaseBegan){
UITouch *touch = [allTouches anyObject];
if (touch.type == UITouchTypeStylus) {
[[NSNotificationCenter defaultCenter] postNotificationName:@"DisableScroll" object:self];
}
else
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"EnableScroll" object:self];
}
}
}
}
@end
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, NSStringFromClass([MyUIApplication class]), NSStringFromClass([AppDelegate class]));
}
}
在包含滚动视图的类中添加这些通知的观察者,并相应地启用/禁用滚动。