Reputation: 371
I want to control the drawing of my UIBezierPath using a UISlider.
The aim is to be able to scrub the timeline (UISlider) and cause the line (UIBezierPath) to draw based on the current position of the slider.
So that when I scrub forward the path renders forward & when I scrub back the path renders backwards.
I have the code to render the path drawing in both directions based on this sample code which I added reverse path to (https://github.com/ole/Animated-Paths)
The main thing I am struggling to understand is how can I have the path render when I move the slider since I cant really use animations as they would not update with the sliders movement..
Cheers Damien
Upvotes: 0
Views: 618
Reputation: 371
So I found that I was unable to use animations to achieve what I wanted so I used a custom UIView subclass and implemented in its drawRect method the code to handle the animations
Basically I set a index in the subclass that controlled how many of the points the drawrect method draws.
This gave me the desired approach and allowed me to change the value based on the slider.
For the drawing I used CGContextMoveToPoint & CGContextAddLineToPoint to render the paths
Cheers
Upvotes: 0
Reputation: 3126
If you are tracking the "Control Events" of the UISlider, for example like this:
[yourSlider addTarget:self action:@selector(seekBegan:) forControlEvents:UIControlEventTouchDown];
[yourSlider addTarget:self action:@selector(seekContinues:) forControlEvents:UIControlEventTouchDragInside];
[yourSlider addTarget:self action:@selector(seekEnded:) forControlEvents:UIControlEventTouchUpInside];
.. you can then do your animations inside "seekContinues:". I can't say how smooth it will be though! as there may be a lot of calls to that method.
Upvotes: 1