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
could problem view container, , how can fix this?
thank if you've read whole thing.
Comments
Post a Comment