ios - cancelTracking called unexpectedly when dragging in customized segmented control -


i'm using customized segmented control this tutorial, in addition, selected segment changed on swipe/drag, added these functions:

override func begintracking(_ touch: uitouch, event: uievent?) -> bool {     super.begintracking(touch, with: event)      let location = touch.location(in: self)     lasttouchlocation = location      return true }  override func continuetracking(_ touch: uitouch, event: uievent?) -> bool {     super.continuetracking(touch, with: event)      let location = touch.location(in: self)     print(location.x - lasttouchlocation!.x)      let newx = thumbview.frame.origin.x + (location.x - lasttouchlocation!.x)     if frame.minx <= newx && newx + thumbview.frame.width <= frame.maxx {         thumbview.frame.origin.x = newx     }     lasttouchlocation = location      return true }  override func endtracking(_ touch: uitouch?, event: uievent?) {     super.endtracking(touch, with: event)      let location = touch != nil ? touch!.location(in: self) : lasttouchlocation!      var calculatedindex : int?     (index, item) in labels.enumerated() {         if item.frame.contains(location) {             calculatedindex = index         }     }      if calculatedindex != nil && calculatedindex != selectedindex {         selectedindex = calculatedindex!         sendactions(for: .valuechanged)     } else {         displaynewselectedindex()     } } 

i've embedded control in uiview container, somehow touch gets canceled when drag thumb view short distance

enter image description here

could problem view container, , how can fix this?

thank if you've read whole thing.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -