• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Animating bounds/position when layer.transform is set, or how to orient an image
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Animating bounds/position when layer.transform is set, or how to orient an image


  • Subject: Animating bounds/position when layer.transform is set, or how to orient an image
  • From: Gabriel Zachmann via Cocoa-dev <email@hidden>
  • Date: Mon, 23 Sep 2019 20:50:46 +0200

Have a layer that displays an image and has some animations attached.
The animations modify layer.bounds (just the size changes)
and layer.position .

Everything works fine, EXCEPT when the image's orientation EXIF flag is set.

So, I am also setting the layer.transform to a transformation that brings the
image into its correct, upright orientation.
This works, EXCEPT that the animations are now off. They still do some
animations , but the bounds and positions
are not correct any more.

Below are some code excerpts to make this more concrete
and to show how I attempted to deal with the orientation flag of the images.

My main questions are:
Does anyone have experience with this case, i.e., animations of layers that
show images that have a non-upright EXIF orientation?
Is there a better/different way of handling non-upright EXIF orientation flags
of images, something other than setting the transformation of the layer
(layer.transform) ?

All hints and insights will be highly appreciated.

Best regards, Gabriel


Encl:

Here are more details.

Here is a code excerpt:

CALayer * imgLayer = [CALayer layer];
imgLayer.contents    = (__bridge id) imageRef;
imgLayer.anchorPoint  = CGPointMake( 0.0, 0.0 );
CGAffineTransform img_trf = ... compute a CGAffineTransform based on the EXIF
orientation flag (in [1,8])   (*)
imgLayer.transform = CATransform3DMakeAffineTransform( img_trf );

CABasicAnimation * anim = ... set up the animation(s)

... compute NSRect from_rect, to_rect  that will be used to set up the
animations of the layer ...
from_rect = CGRectApplyAffineTransform( from_rect, img_trf );
anim.fromValue = [NSValue valueWithRect: from_rect ];
to_rect = CGRectApplyAffineTransform( to_rect, img_trf );
anim.toValue = [NSValue valueWithRect: to_rect ];

NSPoint fromPos = NSMakePoint( ... );
fromPos = CGPointApplyAffineTransform( fromPos, img_trf );
anim.fromValue = [NSValue valueWithPoint: fromPos];
... similarly for anim.toValue ...


So, for instance, if orientation==2, this means that the image is horizontally
flipped.
So, the transformation img_trf I compute is
  img_trf = CGAffineTransformMake(-1.0, 0.0, 0.0, 1.0, 0.0, 0.0);
i.e., the x-coord is flipped.
The CGRectApplyAffineTransform() call does not change the rectangles, which is
reasonable.
The x-coord of fromPos and toPos are flipped (sign is inverted), as expected.
BUT the animation does not do what it should , the image is way off the screen.


I have, of course, also tried without any transformations on the bounds
(from_rect, to_rect)
and without transforming anim.fromValue, anim.toValue.
But then the (oriented) image was completely invisible , maybe way off the
screen.
So, it seems that the CALayer's transformation machinery does not take care of
adjusting bounds/position when a layer's transform is set.




Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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

  • Prev by Date: Re: Views without any layout constraints may clip their content or overlap other views
  • Next by Date: Re: Views without any layout constraints may clip their content or overlap other views
  • Previous by thread: Re: Views without any layout constraints may clip their content or overlap other views
  • Next by thread: Xcode 11 can't make an objective-C subclass any more?
  • Index(es):
    • Date
    • Thread