我有一个UIControl(UIView的子类),当我创建它并将它对齐到我的视图控制器的左侧时,当我触摸视图时,"beginTrackingWithTouch"无法被调用.它只会在我释放触摸时被调用.奇怪的是,当我触摸UIControl时会立即调用pointInside(point:CGPoint ...)方法,甚至更奇怪的是当我在视图控制器的右侧对齐这个UIControl视图时,它工作正常 - 触摸视图时立即调用-beginTrackingWithTouch,而不是在释放时调用.另外,在调用endTrackingWithTouch的同时调用beginTrackingWithTouch.通过一些测试,它工作正常,直到视图从左侧20像素,然后这个奇怪的问题再次发生.
有没有理由说UIControl continueTrackingWithTouch如果放在视图控制器的最左侧则无法注册?这是Apple防止左手滚动的方式吗?左侧绝对没有阻挡UIControl的东西.
//In public class CustomScrollBar : UIControl
//This method gets called everytime when UIControl (red area in picture) is touched
override public func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool {
return CGRectContainsPoint(handleHitArea, point)
}
//Only gets called when UIControl is touched and let go. It will not get called until your finger lifts off the screen.
override public func beginTrackingWithTouch(touch: UITouch, withEvent event: UIEvent?) -> Bool {
self.scrollerLine.hidden = true
if let delegate = self.delegate {
delegate.beginTrackingWithTouch()
}
guard self.isHandleVisible else{
return false
}
self.lastTouchLocation = touch.locationInView(self)
self.isHandleDragged = true
self.setNeedsLayout()
return true
}
Run Code Online (Sandbox Code Playgroud)
//下图:UIControl视图位于左侧(浅蓝色).如果我在最右侧移动它,方法注册正常.
导航控制器有一个内置的后退手势识别器,将其设置为 false。确保它已在 viewDidAppear 中设置
self.navigationController!.interactivePopGestureRecognizer!.enabled = false
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
116 次 |
| 最近记录: |