缺少UIView的anchorPoint属性

时间:2011-07-11 09:39:35

标签: iphone objective-c ios uiview

我正在使用来自apple Touches code的略微改编的代码(我刚刚将片段的变量名称更改为图片):

- (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;
    }
}

但是,如评论中所述,image.layer.anchorPoint无法编译,但错误是无法找到'anchorPoint'属性。它在使用消息传递重写行时进行编译,但它仍会发出警告。

直接复制和粘贴Touches代码而不更改变量名称会产生相同的错误。当我编译Touches代码时,这些错误也不会出现。

为什么会这样?

2 个答案:

答案 0 :(得分:22)

您可能没有包含使用CALayer所需的QuartzCore框架。

您需要添加

#import <QuartzCore/QuartzCore.h>

答案 1 :(得分:4)

您是否将QuartzCore框架添加到项目中?