ios - UIControl 触摸 VC 左侧的行为不正确

标签 ios uitouch

我有一个 UIControl(UIView 的子类),当我创建它并将其与 View Controller 中的左侧对齐时,“beginTrackingWithTouch”在我触摸 View 时无法调用。只有当我释放触摸时它才会被调用。奇怪的是当我触摸 UIControl 时 pointInside(point: CGPoint...) 方法被立即调用,更奇怪的是当我将这个 UIControl View 对齐到 View Controller 的右侧时,它工作正常 - -beginTrackingWithTouch 在触摸 View 时立即调用,而不是在释放时调用。此外,在调用 endTrackingWithTouch 的同时调用了 beginTrackingWithTouch。通过一些测试,它工作正常,直到 View 距离左侧 20 px,然后再次出现这个奇怪的问题。

如果将 UIControl continueTrackingWithTouch 放在 View Controller 的最左侧,是否存在无法注册的原因?这是苹果防止左手滚动的方法吗?左侧绝对没有任何东西阻挡 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
}

//下图:UIControl View 在左侧(浅蓝色)。如果我将它移到最右侧,方法就可以正常注册。

enter image description here

最佳答案

导航 Controller 有一个内置的后退手势识别器,将其设置为 false。确保它在 viewDidAppear 中设置

self.navigationController!.interactivePopGestureRecognizer!.enabled = false

关于ios - UIControl 触摸 VC 左侧的行为不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38626013/

相关文章:

iphone - UIControl 未接收到触摸

ios - 如何检测 View 中的某些部分

ios - 有没有办法在 iOS 中中断事件的 UITouch

android - 手机应用程序中的短信注册 : whatsapp

ios - Swift UnitTesting 测试 2 个可选变量

ios - 从 HealthKit 获取设备

Swift OS X NSTouch 阶段 rawInput 到字符串?

iphone - 有什么方法可以将现有用户添加到 "paid list"以进行新的 iOS 应用内购买?

iphone - 缩放 MKMapView 以适应折线点

ios - event.touchesForView().AnyObject() 在 Xcode 6.3 中不起作用