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 aka shot cgpoint を、互換性のないタイプのパラメータ UIOffset 別名別の UIOffset に送信する

私が間違っていること、またはこれを修正する方法を教えていただければ幸いです。

ありがとう

4

2 に答える 2

0

attachmentPointこれは、CGPointtypeを渡しているためです。変数の型を作成し、UIOffset代わりにその変数を渡す必要がありますattachmentPoint

于 2013-09-26T10:58:50.783 に答える
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 に答える