0

我下载了苹果“DynamicsCatalog.xcodeproj”的示例代码,我遇到了这个问题

- (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;
}

我在哪里替换这条线:

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

用这条线:

 UIAttachmentBehavior *attacheMentBehavior = [[UIAttachmentBehavior alloc] initWithItem:self.square1 offsetFromCenter:attachmentPoint attachedToAnchor:squareCenterPoint];

但我收到此错误:

将 cgpoint 又名击中 cgpoint 发送到不兼容类型 UIOffset 又名击中 UIOffset 的参数

如果您能告诉我我做错了什么或如何解决此问题,我将不胜感激。

谢谢

4

2 回答 2

0

这样做 -

   UIOffset attachmentPoint = UIOffsetMake (-25.0, -25.0);

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

希望这可以帮助!!

于 2013-11-07T05:35:51.767 回答
0

这是因为您传递attachmentPoint的是CGPoint类型。您必须创建一种UIOffset变量并传递该变量而不是您的attachmentPoint.

于 2013-09-26T10:58:50.783 回答