My app has a view that's kept off-screen normally, but slides in from the left when you change focus into it. However, it's pretty easy to accidentally open this pane by making a sweeping slide to the left that overshoots a little. Is there a way to avoid that?
Ideally, I'd like to prevent a focus change if it's part of a gesture that has already caused other focus changes, but I don't see a way to detect that. The best trick I've found so far is to measure the time between focus changes and prevent it if it's too short, but I can't seem to find a sweet spot where a decelerating gesture is always rejected but a series of quick intentional ones isn't:
private let durationBetweenDiscreteFocusChanges = 0.3
<snip>
private func locationOfView(view: UIView) -> ViewLocation {
if (slidingViewController?.view).map(view.isDescendantOfView) ?? false {
return .InSlidingView
}
else if (fixedViewController?.view).map(view.isDescendantOfView) ?? false {
return .InFixedView
}
return .InNeitherView
}
<snip>
override func shouldUpdateFocusInContext(context: UIFocusUpdateContext) -> Bool {
if NSDate() - dateOfLastFocusChange < durationBetweenDiscreteFocusChanges {
if let previousFocusLocation = context.previouslyFocusedView.map(locationOfView), nextFocusLocation = context.nextFocusedView.map(locationOfView) {
if previousFocusLocation != nextFocusLocation && previousFocusLocation != .InNeitherView && nextFocusLocation != .InNeitherView {
return false
}
}
}
return super.shouldUpdateFocusInContext(context)
}(dateOfLastFocusChange is updated in didUpdateFocus.)
Any better ideas? Should I file a radar?