首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >只在x轴中使用UISnapBehaviour

只在x轴中使用UISnapBehaviour
EN

Stack Overflow用户
提问于 2014-03-18 08:52:41
回答 2查看 1K关注 0票数 2

不管怎么说,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;

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-03-18 09:46:18

我将发布我用来做类似事情的代码,正如我在评论中提到的,它使用了UIView动画,它利用了底层的UIKit动态,而不是直接使用它们.

代码语言:javascript
复制
[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];
                 }];

这显示了模态视图,该视图在演示时会产生一些振荡。

票数 0
EN

Stack Overflow用户

发布于 2015-01-21 16:01:31

UIDynamicBehavior文档 of it的action块:

@property(nonatomic, copy) void (^action)(void) 动态动画师在每个动画步骤上调用动作块。

所以,在创造你的行为时,做这样的事情:

代码语言:javascript
复制
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。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22474371

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档