iphone - 发送cgpoint也被击中cgpoint到不兼容类型UIOffset的参数,也被击中 UIOffset

  显示原文与译文双语对照的内容

我下载了苹果"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

如果你能让我知道我在做什么,或者如何修复这个问题,我会非常感激。

谢谢

时间: 原作者:

这是因为你传递的attachmentPointCGPoint 类型。 你必须创建一个 UIOffset 类型的变量,并传递该变量而不是你的attachmentPoint

原作者:

这样做-


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

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

希望这是有帮助的 !

原作者:
...