I recently wrote a custom view — a 3D vintage-looking pull lever — that provided a continuous property to control the state. I wanted to animated this smoothly, a-la CABasicAnimation, but couldn’t find a built-in way to do so.
So, I wrote a class that provides similar functionality to CABasicAnimation, but works on any object. I thought I’d share it.
Features:
- From/to value settings (currently only supports
NSNumberand scalar numeric types, but easily extendable) - Duration, delay settings
- Timing functions: Linear, ease out, ease in, and ease in/ease out
- Animation chaining (specify another configured animation for
chainedAnimation, and it’ll be fired once the first animation completes) - Delegate notification of animation completion
- Uses a single timer for smooth lock-step animation
- Uses
CADisplayLinkif available, to update in sync with screen updates
Use it like this:
- (void)startMyAnimation { TPPropertyAnimation *animation = [TPPropertyAnimation propertyAnimationWithKeyPath:@"state"]; animation.toValue = [NSNumber numberWithFloat:1.0]; // fromValue is taken from current value if not specified animation.duration = 1.0; animation.timing = TPPropertyAnimationTimingEaseIn; [animation beginWithTarget:self]; }
Make sure you also include the QuartzCore framework, used to access CADisplayLink, if it’s available.
It’s BSD-licensed.
Grab it here: TPPropertyAnimation.zip




A trick for capturing all touch input for the duration of a touch
If you’ve ever tried to implement an interactive control that makes use of gestures within a UITableView, or tried to implement a view that you can drag around, like pins on a MKMapView, you’ll know that you’re either generally thwarted by the scroll view (and the table view will just scroll, instead of your control getting the vertical drag gesture), or as soon as the touch moves outside the bounds of your view, you’ll get no more
touchesMovedevents, making for a very frustrating dragging interaction.Some platforms give you a way to capture all pointer input for a time, but this doesn’t appear to be available out of the box on the iPhone — at least, I haven’t found it.
Here’s a way to make it work:
sendEvent:with your own methodWhen you receive a touch began event, check to see if the touch was within the bounds of any ‘priority’ views – if they are, the view subsequently gets all events until the touch ended event.
Read More »