Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing anchorPoint property for UIView

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?

like image 443
zlog Avatar asked Jul 11 '11 09:07

zlog


2 Answers

You probably haven't included the QuartzCore framework, which is required to use CALayer.

You need to add

#import <QuartzCore/QuartzCore.h>
like image 134
omz Avatar answered Oct 15 '22 23:10

omz


Did u add the QuartzCore framework to your project?

like image 41
Ilanchezhian Avatar answered Oct 16 '22 01:10

Ilanchezhian