small medium large xlarge

Generic-user-small
17 Jun 2009, 20:44
Christoph Ludwig (13 posts)

Hi,

a CATransition instance of type kCATransitionPush brings up the full new image left of its future position and then moves it in place, pushing out the previous image that only vanishes once it has been completely displaced.

I need a similar transition, but it has to be clipped to its superlayer’s bound (that’s completely taken up by the images frame). I.e., you see only the part of the image that is already within its future bound (or that is still within its past bounds, in the case of the outgoing image). Has somebody an idea how to do that on the iPhone?

Thanks!

Christoph

Biopic_100x100_pragsmall
18 Jun 2009, 12:17
Bill Dudney (917 posts)

Hi Christoph,

In iPhone 3.0 you can set a layer to mask to its bounds. Will that do what you are looking for?

Generic-user-small
19 Jun 2009, 06:25
Christoph Ludwig (13 posts)

Hi Bill,

you mean masks rather than masksToBounds? I’ll have to give it a try, I will report back.

Regards

Christoph

Generic-user-small
25 Jun 2009, 19:10
Christoph Ludwig (13 posts)

Hi Bill,

if I put an all-white image in a layer that has exactly the same size as my other images and assign it to my superlayer’s mask property, then the push transitions are indeed clipped to the superlayer’s bounds. It’s a pitty that the maskToBounds property does not achieve the same result, since the management of the mask layers makes my code more complex and slower.

But thanks for pointing out the mask property anyway, at least it does the job!

Regards

Christoph

Generic-user-small
24 Jul 2009, 00:51
Drew McAuliffe (1 post)

Any chance of an example of that? I’ve been struggling to get push transitions to work without “ghosting” themselves to the left or right, with no luck.

Generic-user-small
27 Jul 2009, 16:27
Christoph Ludwig (13 posts)

I don’t have any code readily available that I could post, but using the masks property was mostly straight forward:

Let S be the superlayer. It holds an (image) layer L1 such that S.bounds = L1.frame. The transition replaces L1 with another layer L2, L2.frame = L1.frame. # create a PNG with exactly the same size L1. The PNG has to be completely opaque. (I simply made it a white rectangle with alpha = 100%.) # load the PNG as a UIImage P. # create a new layer M, M.frame = S.bounds, and set M.contents = (id)[P CGImage]. # set S.mask = M.

Apparently, Core Animation treats any pixel that falls outside M’s bounds as fully transparant.

Unfortunately, I did not find documentation if L becomes M’s superlayer, i.e. if is sufficient to set L.mask = nil if you want to re-use the mask or if you also have to call [M removeFromSuperlayer] or if the latter is actually the intended way to severethe connection between a layer and its mask. In the end, I did both.

For unrelated reasons I had to introduce an additional layer H inbetween S and L1. (So now L1.superlayer = H and H.superlayer = S.) Then I could forgo setting S.masks: Simply setting S.masksToBounds = YES turned out to be sufficient as soon as the transition did no longer act on S’s direct sublayers anymore but on S’s “grandchildren”.

HTH, Christoph

You must be logged in to comment