我(以及其他许多人)已经注意到Apple改变了popover控制器的外观以使用“滑块”窗口而不是我使用过的通常的“popover”tableview。虽然我对新外观感到满意,但与其他人一样,我遇到了滑动手势的问题:
iOS 5.1 swipe gesture hijacked by UISplitViewController - how to avoid?
对此的修复似乎是将拆分视图控制器方法“presentWithGesture”设置为“NO。”
UISplitViewController *splitViewController = [[UISplitViewController alloc] init];
splitViewController.presentsWithGesture = NO;
如果用户使用iOS 5.1,这很有用,但是,如果使用iOS 5.0或更低版本运行此代码,则抛出异常,因为此方法仅适用于iOS 5.1:
Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: '-[UISplitViewController setPresentsWithGesture:]: unrecognized selector
是否可以在不使用此方法的情况下摆脱此手势,以便向后兼容iOS 5.0及以下版本?
答案 0 :(得分:9)
对于任何类型的向后兼容性,首先检查是否存在新属性的setter方法...
if ([mySplitViewController respondsToSelector:@selector(setPresentsWithGesture:)]) {
[mySplitViewController setPresentsWithGesture:NO];
}
请注意,在将UISplitViewController.view添加到窗口之前,显然需要执行此操作。我猜测在那时检查属性并添加手势识别器。如果在添加视图后更改属性,则它没有明显的效果。