• 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
Re: Getting the true rotation of a UIView layer
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting the true rotation of a UIView layer


  • Subject: Re: Getting the true rotation of a UIView layer
  • From: Graham Cox <email@hidden>
  • Date: Wed, 15 Mar 2017 15:26:38 +1100

Hmm, you’ll need to use the CGAffineTransform because it has a richer set of functions than CATransform3D. This will only work if the 3D transform can be converted to a CGAffineTransform, which it can if the rotation is purely in the 2D plane - i.e. no Z transformations.


CGAffineTransform cgt = CATransform3DGetAffineTransform( myLayer.transform );

CGPoint newPt = CGPointApplyAffineTransform( CGPointMake( 100, 0 ), cgt );	// this point only has an x value, so its angle is 0. The value doesn’t matter

CGFloat angle = atan2( newPt.y, newPt.x );



You can probably do the same by getting values out of the transform directly as you tried, except that you really have to know your trig. The values in there (which?) represent sin and cos of the angle, so in theory using tan(x) = sin(x)/cos(x) you could get the angle that way, but I prefer to treat transforms as black boxes and just transform a known point and see where it ends up. That way you don’t need to know how the transform’s internals are laid out.


> On 15 Mar 2017, at 2:41 PM, Eric E. Dolecki <email@hidden> wrote:
>
> I don't follow.
>
> On Tue, Mar 14, 2017 at 11:29 PM Graham Cox <email@hidden> wrote:
> Get the final transform, then use it to transform an angle of 0. The result is the angle.
>
> —Graham


_______________________________________________

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


References: 
 >Getting the true rotation of a UIView layer (From: "Eric E. Dolecki" <email@hidden>)
 >Re: Getting the true rotation of a UIView layer (From: Graham Cox <email@hidden>)
 >Re: Getting the true rotation of a UIView layer (From: "Eric E. Dolecki" <email@hidden>)

  • Prev by Date: Re: Getting the true rotation of a UIView layer
  • Next by Date: NSTableView column sizes
  • Previous by thread: Re: Getting the true rotation of a UIView layer
  • Next by thread: NSTableView column sizes
  • Index(es):
    • Date
    • Thread