2

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:

  1. Check the iOS version, which I don't know how to do, or
  2. 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.

Sam
  • 26,946
  • 12
  • 75
  • 101

1 Answers1

4
BOOL isAtLeastIOS5 = [[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0;

See How to test a protocol for a method? to test the protocol for a given method.

Community
  • 1
  • 1
Jano
  • 62,815
  • 21
  • 164
  • 192
  • Nitpicking... rename BOOL to isAtLeastIOS5 ;) – Till Nov 08 '11 at 16:52
  • +1 That looks easy enough and may be what I use. I'd still like to figure out how to check if the protocol defines the method. I wonder if something similar to `instancesRespondsToSelector:` would work. Still trying to figure it out myself... I'll accept this as answer if I don't see anything better. – Sam Nov 08 '11 at 16:53
  • `[[[UIDevice currentDevice] systemVersion] floatValue] > 4.3;` is true for iOS 4.3.3, so this should be `[[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0;` – Dorian Roy Jan 21 '12 at 12:08