问题
I've (along with many others) have noticed that Apple changed the appearance of the popover controller to use a "slider" window rather than the usual "popover" tableview that I've used. While I'm okay with the new appearance, like others I'm having issues with the swipe gesture that is introduced:
iOS 5.1 swipe gesture hijacked by UISplitViewController - how to avoid?
The fix for this seems to be to set the split view controller method "presentWithGesture" to "NO."
UISplitViewController *splitViewController = [[UISplitViewController alloc] init];
splitViewController.presentsWithGesture = NO;
This works great if the user is using iOS 5.1, however, if this code is run using iOS 5.0 or below, an exception is thrown since this method is only available for iOS 5.1:
Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[UISplitViewController setPresentsWithGesture:]: unrecognized selector
Is it possible to get rid of this gesture without using this method so that it's backwards compatible with iOS' 5.0 and below?
回答1:
For any type of backward compatibility, check for the presence of the setter method for the new property first...
if ([mySplitViewController respondsToSelector:@selector(setPresentsWithGesture:)]) {
[mySplitViewController setPresentsWithGesture:NO];
}
Note that apparently you need to do this before you add the UISplitViewController.view to your window. I'm guessing that at that point the property is examined and the gesture recognizer is added or not. If you change the property after adding the view, it has no discernible effect.
来源:https://stackoverflow.com/questions/10078616/uipopovercontroller-gesture-handling-in-uisplitviewcontroller-for-ios-5-1-and-be