• 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: Rotated CALayer and issues with coordinates (should I convert them manually?)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Rotated CALayer and issues with coordinates (should I convert them manually?)


  • Subject: Re: Rotated CALayer and issues with coordinates (should I convert them manually?)
  • From: David Duncan <email@hidden>
  • Date: Mon, 29 Apr 2013 00:33:27 -0700

On Apr 27, 2013, at 2:48 AM, Daniele Margutti <email@hidden> wrote:

> If I try to rotate my hostView.layer (CALayer) using the function below I get wrong coordinates when I try to click at the same (rotated) point (the top,left coordinate of hostView)

Point conversion happens via the model layer, not the presentation layer. By rotating the layer the way you've done, you've only changed the presentation layer, rather than the model, and thus the hit testing fails.

Instead just set the layer's transform. If you want to customize the duration then use the +[CATransaction setAnimationDuration:]. No need to get into explicit animation and the many pitfalls that typically accompany it.

>
>
> - (IBAction)btn_rotateHostView:(id)sender {
>     isMovingToLandscape = !isMovingToLandscape;
>     CALayer *hostViewLayer = hostView.layer;
>     hostViewLayer.anchorPoint = CGPointMake(0.5f, 0.5f); // 0.5,0.5 made the center of the object
>     hostViewLayer.frame = CGRectMake((NSWidth(baseContainerView.frame) - NSWidth(hostViewLayer.frame)) / 2.0f,
>                                           (NSHeight(baseContainerView.frame) - NSHeight(hostViewLayer.frame)) / 2.0f,
>                                           hostViewLayer.frame.size.width,
>                                           hostViewLayer.frame.size.height);
>     [CATransaction begin];
>     CABasicAnimation* animation = [CABasicAnimation animationWithKeyPath: @"transform"];
>     CATransform3D rotateTransform = CATransform3DMakeRotation (DEGREES_TO_RADIANS (-90), 0, 0, 1);
>     CATransform3D restoreTransform = CATransform3DIdentity;
>     animation.fromValue = [NSValue valueWithCATransform3D: (isMovingToLandscape ? restoreTransform : rotateTransform)];
>     animation.toValue = [NSValue valueWithCATransform3D: (isMovingToLandscape ? rotateTransform : restoreTransform)];
>     animation.duration = 1.25;
>     animation.cumulative = NO;
>     animation.removedOnCompletion = NO;
>     animation.fillMode = kCAFillModeForwards;
>     [hostViewLayer addAnimation:animation forKey:@"transform"];
>     [CATransaction commit];
> }
>
>
> This is a visual feeback:
> http://i.imgur.com/LYywXXL.png
>
> While here i've uploaded source code
> https://dl.dropboxusercontent.com/u/103260/TestinLayer.zip
>
> Should I convert coordinates manually? Or convertPoint: methods take in place rotation transform?
> I should expect 4,5 at the same "logical" point (top-left of rotated hostView)
> Any idea?
> _______________________________________________
>
> 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

--
David Duncan


_______________________________________________

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

  • Follow-Ups:
    • Re: Rotated CALayer and issues with coordinates (should I convert them manually?)
      • From: Daniele Margutti <email@hidden>
References: 
 >Rotated CALayer and issues with coordinates (should I convert them manually?) (From: Daniele Margutti <email@hidden>)

  • Prev by Date: Re: LSGetApplicationForURL() failed Error -10814
  • Next by Date: Re: Rotated CALayer and issues with coordinates (should I convert them manually?)
  • Previous by thread: Rotated CALayer and issues with coordinates (should I convert them manually?)
  • Next by thread: Re: Rotated CALayer and issues with coordinates (should I convert them manually?)
  • Index(es):
    • Date
    • Thread