I’m using slightly adapted code from apple’s Touches code (I’ve just changed the variable name of piece to image):
- (void)adjustAnchorPointForGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer {
if (gestureRecognizer.state == UIGestureRecognizerStateBegan) {
UIView *image = gestureRecognizer.view;
CGPoint locationInView = [gestureRecognizer locationInView:image];
CGPoint locationInSuperview = [gestureRecognizer locationInView:image.superview];
// Gives error: Property 'anchorPoint' not found on object of type 'CALayer *'
//image.layer.anchorPoint = CGPointMake(locationInView.x / image.bounds.size.width, locationInView.y / image.bounds.size.height);
// Gives warning: Method '-setAnchorPoint' not found
[image.layer setAnchorPoint:CGPointMake(locationInView.x / image.bounds.size.width, locationInView.y / image.bounds.size.height)];
image.center = locationInSuperview;
}
}
However, as stated in the comments, image.layer.anchorPoint doesn’t compile, with an error of not being able to to find the ‘anchorPoint’ property. It compiles when the line is rewritten with message passing, but it still gives a warning.
Copy and pasting the Touches code directly without the variable name changes gives the same error. Also these errors don’t appear when I compile the Touches code.
Why is this?
You probably haven’t included the QuartzCore framework, which is required to use
CALayer.You need to add