我使用的是来自苹果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代码时,这些错误也不会出现。
为什么会这样呢?
发布于 2011-07-11 17:46:15
您可能还没有包括使用CALayer所需的QuartzCore框架。
您需要添加
#import <QuartzCore/QuartzCore.h>发布于 2011-07-11 17:50:08
你将QuartzCore框架添加到你的项目中了吗?
https://stackoverflow.com/questions/6648285
复制相似问题