0

我有以下代码,它只是将密码附加UITextFieldanchorPoint. 当我运行它时,什么也没有发生。

UIDynamicItemBehavior *behavior = 
 [[UIDynamicItemBehavior alloc] initWithItems:@[passwordTextField]];

CGPoint anchor = passwordTextField.center;
anchor.y -= 200;

_attachment = [[UIAttachmentBehavior alloc] initWithItem:passwordTextField 
                                        attachedToAnchor:anchor];

_gravity = [[UIGravityBehavior alloc] initWithItems:@[passwordTextField]];
_gravity.magnitude = 10;

[behavior addChildBehavior:_gravity];
[behavior addChildBehavior:_attachment];

[_animator addBehavior:behavior];
4

1 回答 1

1

附件不会更改项目的位置。相反,它只会使项目和附着点之间的距离固定。

如果您想修改距离,请尝试 UISnapBehavior。

于 2014-01-14T14:41:33.160 回答