我正在使用来自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代码时,这些错误也不会出现。
为什么会这样?
答案 0 :(得分:22)
您可能没有包含使用CALayer
所需的QuartzCore框架。
您需要添加
#import <QuartzCore/QuartzCore.h>
答案 1 :(得分:4)
您是否将QuartzCore框架添加到项目中?