2016-07-28 3 views
5

UIControl (UIView의 하위 클래스)을 만들고이를 뷰 컨트롤러의 왼쪽에 정렬하면 "beginTrackingWithTouch"가 호출 될 때 호출되지 않습니다. 보기를 터치하십시오. 터치를 놓을 때만 호출됩니다. 이상한 점은 UIControl을 만질 때 pointInside (point : CGPoint ...) 메서드가 즉시 호출된다는 것입니다. 심지어 더 이상한 것은 뷰 컨트롤러의 오른쪽에이 UIControl 뷰를 정렬하면 잘 동작합니다. -beginTrackingWithTouch는 뷰가 터치 될 때 즉시 호출되며 해제되지 않을 때 호출됩니다. 또한 beginTrackingWithTouch가 호출되는 것과 동시에 endTrackingWithTouch가 호출됩니다. 몇 가지 테스트를 통해보기가 왼쪽에서 20px가 될 때까지 정상적으로 작동하지만이 이상한 문제가 다시 발생합니다.VC의 왼쪽에서 UIControl이 올바르게 동작하지 않습니다.

뷰 컨트롤러의 맨 왼쪽에 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 
} 

// 아래 이미지 : UIControl보기는 왼쪽 (연한 파란색)입니다. 맨 오른쪽으로 이동하면 메소드가 잘 등록됩니다.

enter image description here

+1

이보기 컨트롤러에는 navi 컨트롤러가 있습니까? 만약 있다면, navi 컨트롤러는 edge 제스처 (interactivePopGestureRecognizer)를 가지고 있습니다. – zylenv

답변

2

네비게이션 컨트롤러가 다시 제스처 인식기가 내장되어, false로 설정합니다. viewDidAppear에 설정되어 있는지 확인하십시오.

self.navigationController!.interactivePopGestureRecognizer!.enabled = false 
+0

예 감사합니다. 나는 ViewDidLoad에서 그것을 가졌다. –

관련 문제