Ios 检查是否定义了协议方法
有一个新的很棒的方法:Ios 检查是否定义了协议方法,ios,objective-c-runtime,uiscrollviewdelegate,Ios,Objective C Runtime,Uiscrollviewdelegate,有一个新的很棒的方法: // called on finger up if the user dragged. velocity is in points/second. targetContentOffset may be changed to adjust where the scroll view comes to rest. not called when pagingEnabled is YES - (void)scrollViewWillEndDragging:(UIScrollVi
// called on finger up if the user dragged. velocity is in points/second. targetContentOffset may be changed to adjust where the scroll view comes to rest. not called when pagingEnabled is YES
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView
withVelocity:(CGPoint)velocity
targetContentOffset:(inout CGPoint *)targetContentOffset __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0)
但是,这仅在iOS 5中可用。对于没有这种方法的iOS,我想使用分页作为替代方法。所以我有两个选择:
respondsToSelector:
检查是不够的,因为实现协议的类将始终定义它
BOOL isAtLeastIOS5 = [[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0;
有关协议成员可用性的有趣问题,请参阅测试给定方法的协议。+1。挑剔。。。将布尔重命名为isAtLeastIOS5;)+1看起来很简单,可能就是我用的。我仍然想弄清楚如何检查协议是否定义了方法。我想知道类似于
instanceRespondsToSelector:
的东西是否会起作用。我自己还在想办法。。。如果没有更好的答案,我会接受这个答案。[[[UIDevice currentDevice]systemVersion]floatValue]>4.3
对于iOS 4.3.3是真的,因此这应该是[[[UIDevice currentDevice]systemVersion]floatValue]>=5.0代码>