【问题标题】:ARC semantic issue "multiple methods named 'setRotation' " while archiving onlyARC 语义问题“多个名为‘setRotation’的方法”,仅归档时
【发布时间】:2014-04-20 10:49:20
【问题描述】:

我在 cocos2dv3 中的项目抛出 ARC Sematic Issue 发现多个名为“setRotation:”的方法的结果、参数类型或属性不匹配 归档时(发布模式)。它在部署到模拟器/设备(调试模式)时运行良好。 在发布模式下,编译器会混淆 UIRotationGestureRecognizerCCNode 中的轮换实现。 当我在 CCBAnimationManager.m 中遇到错误时,我将调用选择器 setRotation 的对象类型转换为 (CCNode*),但随后错误在 CCActionInterval 中出现。我希望有一个比在 cocos2d 库中到处进行类型转换更好的解决方案。

我做错了什么? 谢谢你的时间。

编辑

@interface CCAction : NSObject <NSCopying> {
    id          __unsafe_unretained _originalTarget;
    id          __unsafe_unretained _target;
    NSInteger   _tag;
}
@property (nonatomic,readonly,unsafe_unretained) id target;
@property (nonatomic,readonly,unsafe_unretained) id originalTarget;
@property (nonatomic,readwrite,assign) NSInteger tag;

CCAction.m
@synthesize tag = _tag, target = _target, originalTarget = _originalTarget;


-(void) startWithTarget:(id)aTarget
{
    _originalTarget = _target = aTarget;
}

-(void) startWithTarget:(id)aTarget
{
    _originalTarget = _target = aTarget;
}

类层次结构

@interface CCActionFiniteTime : CCAction <NSCopying> 
@interface CCActionInterval: CCActionFiniteTime <NSCopying>
@interface CCBRotateTo : CCActionInterval <NSCopying>

CCBRotateTo.m {

   -(void) startWithTarget:(CCNode *)aTarget
   {
      [super startWithTarget:aTarget];
      startAngle_ = [self.target rotation];
      diffAngle_ = dstAngle_ - startAngle_;
   }

   -(void) update: (CCTime) t
   {
      [self.target setRotation: startAngle_ + diffAngle_ * t];
   }

}

【问题讨论】:

  • 在 github 上将其报告为问题。正如您已经指出的,修复只是在弹出此错误的任何地方强制转换为适当的类型(基类)。
  • 贴出导致问题的相关代码。
  • @LearnCocos2D 我会的..
  • @rmaddy 编辑了这个问题。但如果我在这里进行类型转换,问题会再次出现在 CCActionInterval
  • 显示target 属性是如何声明的。

标签: ios objective-c cocos2d-iphone xcode5


【解决方案1】:

将您的 cocos2dv3 更新到最新版本(目前为 RC4)。

我使用 Xcode 5.0 和 cocos2dv3 RC1 没有问题。 但是将 Xcode 更新到 5.1 我遇到了这个问题。 所以我将 cocos2dv3 更新为 RC4,现在它可以正常工作了。

您可以从here 找到 cocos 2d 的最新版本。

【讨论】:

【解决方案2】:

这个问题让我很头疼。虽然我已经将旧项目的 cocos2d 升级到 v2.2 版本(太复杂,无法更新到 v3),但我仍然收到此警告。我在 SpriteBuilder 中使用旋转创建的任何动画都表现得很奇怪,正如我在这里描述的: Rotation animation issue on iPhone5S with cocos2d 2.0

最后我在 CCBAnimationManager.m 中使用了类型转换来解决它

@implementation CCBRotateTo
-(void)startWithTarget:(CCNode *)aTarget
{
    [super startWithTarget:aTarget];
    starAngle_ = [(CCNode *)self.target rotation];
    diffAngle_ = dstAngle_ - startAngle_;
}

-(void)update:(ccTime)t
{
    [(CCNode *)self.target setRotation: startAngle_ + diffAngle_ * t];
}

有了这个改动,现在我也可以支持 arm64 了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-06
    • 1970-01-01
    • 1970-01-01
    • 2020-03-05
    • 1970-01-01
    • 2011-06-28
    相关资源
    最近更新 更多