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:(UIScrollView *)scrollView
withVelocity:(CGPoint)velocity
targetContentOffset:(inout CGPoint *)targetContentOffset __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0)
但是,这仅在 iOS 5 中可用。对于没有这种方法的 iOS,我想使用分页作为替代方法。所以我有两个选择:
- 检查 iOS 版本,我不知道该怎么做,或者
- 检查是否为
UIScrollViewDelegate
协议,我也不知道该怎么做。
我更愿意以某种方式检查该方法是否在协议中定义,而不是检查 iOS 版本。请注意,执行 respondsToSelector:
检查是不够的,因为实现该协议的类将始终定义它。
UIScrollViewDelegate
has a new awesome method:
// 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)
However, this is ONLY available in iOS 5. For iOS's without this method, I'd like to use paging as an alternative. So I'm left with two options:
- Check the iOS version, which I don't know how to do, or
- Check to see if this method is defined for the
UIScrollViewDelegate
protocol, which I also don't know how to do.
I would prefer to somehow check if the method is defined in the protocol rather than checking the iOS version. Note that doing a respondsToSelector:
check won't be adequate since my class implementing the protocol will always define it.
发布评论
评论(1)
请参阅如何测试方法的协议? 测试给定方法的协议。
See How to test a protocol for a method? to test the protocol for a given method.