【问题标题】:sending cgpoint aka struck cgpoint to parameter of incompatible type UIOffset aka struck UIOffset将 cgpoint 又名击中 cgpoint 发送到不兼容类型 UIOffset 又名击中 UIOffset 的参数
【发布时间】:2013-09-26 04:25:31
【问题描述】:

我下载了苹果“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 的参数

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

谢谢

【问题讨论】:

    标签: iphone ios ipad xcode5


    【解决方案1】:

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

    【讨论】:

    • 我很困惑。你能告诉我怎么做吗?
    【解决方案2】:

    这样做 -

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

    希望这会有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多