不管怎么说,UISnapBevahiour是否只能沿着x轴工作?
我想要一个UISnapBehaviour的确切行为,但不希望它在x&y轴上“摇”成一个位置,只是x轴。
这是用于表单元格的contentView中的一个contentView。
// UIKitDynamics self.animator = [UIDynamicAnimator alloc initWithReferenceView:self];CGPoint centerPoint = self.contentView.center;self.snapBehaviour = [UISnapBehavior alloc initWithItem:self.frontView管理点:centerPoint];self.snapBehaviour setDamping:1.0f;self.animator addBehavior:self.snapBehaviour;UIDynamicItemBehavior *itemBehaviour = [UIDynamicItemBehavior alloc initWithItems:@self.frontView];itemBehaviour.elasticity = 0.0f;itemBehaviour.allowsRotation = NO;itemBehaviour.elasticity addBehavior:itemBehaviour;
发布于 2014-03-18 09:46:18
我将发布我用来做类似事情的代码,正如我在评论中提到的,它使用了UIView动画,它利用了底层的UIKit动态,而不是直接使用它们.
[UIView animateWithDuration:0.5
delay:0.0
usingSpringWithDamping:0.5
initialSpringVelocity:0.3
options:UIViewAnimationOptionCurveEaseIn
animations:^{
[toView setFrame:_modalFrame];
}
completion:^(BOOL finished) {
[self.context completeTransition:YES];
}];这显示了模态视图,该视图在演示时会产生一些振荡。
发布于 2015-01-21 16:01:31
从UIDynamicBehavior文档 of it的action块:
@property(nonatomic, copy) void (^action)(void)动态动画师在每个动画步骤上调用动作块。
所以,在创造你的行为时,做这样的事情:
UIView *view = ...
UIAttachmentBehavior *attachment = [[UIAttachmentBehavior alloc] initWithItem:view attachedToAnchor:point];
CGFloat xCoordinate = view.frame.origin.x;
attachment.action = ^{
if (view.frame.origin.x != xCoordinate) {
CGRect frame = view.frame;
frame.origin.x = xCoordinate;
view.frame = frame;
}
};
[self.dynamicAnimator addBehavior:attachment];在我的示例中,我使用UIAttachmentBehavior,但是这个方法也适用于UIDynamicBehavior的任何其他子类,在您的例子中是UISnapBehavior。
https://stackoverflow.com/questions/22474371
复制相似问题