Missing anchorPoint property for UIView

I am using slightly adapted code from apple Binding Code (I just changed the variable name in the 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 indicated in the comments, image.layer.anchorPoint does not compile with an inability to find the "anchorPoint" property error. It compiles when a string is overwritten with a message, but it still gives a warning.

Copying and pasting Touches code directly without changing the variable name gives the same error. Also, these errors do not appear when compiling Touches code.

Why is this?

+6
source share
2 answers

You probably did not include the QuartzCore framework that you want to use CALayer .

You need to add

 #import <QuartzCore/QuartzCore.h> 
+22
source

Have you added the QuartzCore framework project to the project?

+4
source

Source: https://habr.com/ru/post/892473/


All Articles