On Apr 27, 2013, at 2:48 AM, Daniele Margutti <m...@danielemargutti.com> 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 (Cocoa-dev@lists.apple.com)
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/david.duncan%40apple.com
> 
> This email sent to david.dun...@apple.com

--
David Duncan


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to