首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >缺少UIView的anchorPoint属性

缺少UIView的anchorPoint属性
EN

Stack Overflow用户
提问于 2011-07-11 17:39:35
回答 2查看 3.3K关注 0票数 6

我使用的是来自苹果Touches code的略微修改过的代码(我刚刚将片段的变量名改为图像):

代码语言:javascript
复制
- (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代码时,这些错误也不会出现。

为什么会这样呢?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-07-11 17:46:15

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

您需要添加

代码语言:javascript
复制
#import <QuartzCore/QuartzCore.h>
票数 22
EN

Stack Overflow用户

发布于 2011-07-11 17:50:08

你将QuartzCore框架添加到你的项目中了吗?

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6648285

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档