我下载苹果“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 struck cgpoint发送到不兼容类型的参数UIOffset又名为UIOffset
如果你能告诉我我做错了什么或者如何解决这个问题,我将非常感激。
感谢
答案 0 :(得分:0)
这是因为您传递attachmentPoint
CGPoint
类型的UIOffset
。您必须制作attachmentPoint
类型的变量并传递该变量而不是{{1}}。
答案 1 :(得分:0)
这样做 -
UIOffset attachmentPoint = UIOffsetMake (-25.0, -25.0);
UIAttachmentBehavior *attachmentBehavior = [[UIAttachmentBehavior alloc]
initWithItem:self.square1
offsetFromCenter:attachmentPoint
attachedToAnchor:squareCenterPoint];
希望这会有所帮助!!