1

我只是从苹果开发者门户下载 DynamicsCatalog.xcodeproj 但我收到了这个错误:

'UIAttachmentBejavior' 没有可见的@interface 清除选择器 initwititem

在这条线上:

UIAttachmentBehavior *attachmentBehavior = [[UIAttachmentBehavior alloc] initWithItem:self.square1 point:attachmentPoint attachedToAnchor:squareCenterPoint];

在 APLAttachmentsViewController.m

这是该行的上下文:

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIDynamicAnimator* animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
    UICollisionBehavior* collisionBehavior = [[UICollisionBehavior alloc] initWithItems:@[self.square1]];

    CGPoint squareCenterPoint = CGPointMake(self.square1.center.x, self.square1.center.y - 100.0);
    CGPoint attachmentPoint = CGPointMake(-25.0, -25.0);
    /*
     By default, an attachment behavior uses the center of a view. By using a small offset, we get a more interesting effect which will cause the view to have rotation movement when dragging the attachment.
     */
    UIAttachmentBehavior *attachmentBehavior = [[UIAttachmentBehavior alloc] initWithItem:self.square1 point:attachmentPoint attachedToAnchor:squareCenterPoint];

    collisionBehavior.translatesReferenceBoundsIntoBoundary = YES;

    // Show visually the attachment points
    self.redSquare.center = attachmentBehavior.anchorPoint;
    self.blueSquare.center = CGPointMake(25.0, 25.0);

    [animator addBehavior:attachmentBehavior];
    self.animator = animator;

    self.attachmentBehavior = attachmentBehavior;
}

你们中的任何人都知道为什么或如何修复此演示代码吗?

4

2 回答 2

1

查看UIAttachmentBehavior的类参考:initWithItem:point:attachedToAnchor:未声明,它似乎已在某些时候被删除。使用其他初始化程序之一:

– initWithItem:attachedToAnchor:
– initWithItem:attachedToItem:
– initWithItem:offsetFromCenter:attachedToAnchor:
– initWithItem:offsetFromCenter:attachedToItem:offsetFromCenter:

您正在使用的选择器实际上已重命名为initWithItem:offsetFromCenter:attachedToAnchor:

于 2013-09-26T02:28:09.010 回答
0

似乎示例代码使用了在 iOS 7 最终版本之前被替换的选择器。替换选择器是initWithItem:offsetFromCenter:attachedToAnchor:. 此外,该方法UIOffset作为第二个参数(而不是CGPoint)。

这是我使用的代码:

UIOffset attachmentOffset = UIOffsetMake(-25, -25);
UIAttachmentBehavior *attachmentBehavior = [[UIAttachmentBehavior alloc] initWithItem:self.square1 offsetFromCenter:attachmentOffset attachedToAnchor:squareCenterPoint];

attachmentOffset替换attachmentPoint. _

于 2014-05-15T17:52:11.430 回答