nicklockwood / iCarousel

A simple, highly customisable, data-driven 3D carousel for iOS and Mac OS
http://www.charcoaldesign.co.uk/source/cocoa#icarousel
Other
12k stars 2.58k forks source link

2D Carousel #477

Open duke4e opened 10 years ago

duke4e commented 10 years ago

Since iCarousel uses 3D transformations, when you get a screenshot of view iCarousel isn't rendered to the screenshot. That's why I propose to add an option to use 2D transformations. Of course, that means that not all carousel types will look ok, but that's ok with me, and should probably be ok with anyone that needs to make a screenshot.

So, on to the patch:

in compareViewDepth, add something like this:

if (2DMode) {
    CATransform3D t1 = CATransform3DMakeAffineTransform(view1.superview.transform);
    CATransform3D t2 = CATransform3DMakeAffineTransform(view2.superview.transform);
    CATransform3D t3 = CATransform3DMakeAffineTransform([self currentItemView].superview.transform);
} else {
    ... old code
}

and in containView:

if (2DMode) {
    CGAffineTransform affine = CGAffineTransformMake(transform.m11, transform.m12, transform.m21, transform.m22, transform.m41, transform.m42);
    view.superview.transform = affine;
} else {
    ... old code
}

I didn's send this as a pull request so you can think about this idea and implement it in the way that you think is best suitable for iCarousel.

nicklockwood commented 10 years ago

Interesting...

sovannarithsok commented 10 years ago

Could you show us with some example how to capture screenshot with icarousel?

duke4e commented 10 years ago

Screenshot code: https://stackoverflow.com/questions/2200736/how-to-take-a-screenshot-programmatically

Hacked iCarousel (for my personal use): http://www.mediafire.com/download/9488ya5yn8rd1bl/iCarousel.zip

Usage is same as in normal iCarousel, but note that most of transforms don't work as intended since they need a proper 3D translation. Best using iCarouselTypeLinear.

nicklockwood commented 10 years ago

On iOS 7 and above you can use the new [UIView drawViewHierarchyInRect:afterScreenUpdates:] method to capture iCarousel screenshots.

Unfortunately, prior to iOS 7, there is no way to capture iCarousel screenshots. The hack that duke4e implemented works for 2D carousels, but not 3D ones.

creoapp commented 10 years ago

How a complete iCarousel screenshot can be rendered on Mac?

nicklockwood commented 10 years ago

I have no idea, sorry. I do know that [carousel.layer renderInContext:] won't work though.

creoapp commented 10 years ago

Hello, we found a very nice way to have iCarousel screenshot working on Mac and iOS 6/7. If you are interested we can share our code.

nicklockwood commented 10 years ago

Hi @creoapp, yes, I would be interested to know how you achieved this.