Re: Carousel - like control for Mac OS
Re: Carousel - like control for Mac OS
- Subject: Re: Carousel - like control for Mac OS
- From: vincent habchi <email@hidden>
- Date: Wed, 21 Dec 2011 11:55:03 +0100
Nick,
I cannot elaborate much on this and give you code (not because it is somehow confidential, but just because it is a general idea I don’t have implemented, though I’m familiar with CAScrollLayers). The idea is thus:
1. Draw a normal NSView that you back with a CAScrollLayer. Give it the right size.
2. Generate a NSArray of CALayers, each one initialized with a single image.
3. Put as sublayers of your CAScrollLayer as many CALayers as you want images displayed, giving each CALayer origin the right position (ex: (0,0) - (0, 100) - (0, 200) if you display three images of 100x100 pixels each). Your CAScrollLayer should have its origin at (0, 0).
4. Use standard event handling methods to detect mouse click.
5. If you want to scroll, say leftwards, add a new sublayer with the proper image at (0, 300), then animate the origin of the CAScrollLayer from (0,0) to (0, 100). Once the animation is done, you can safely remove the (0, 0) sublayer.
6. Go back to 4.
The NSArray is a sort of cache where the CALayer live. This is more efficient than generating a CALayer on the fly each time you scroll.
Vincent_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden