Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用Interface Builder时的UIKitDynamics_Ios_Objective C_Uiviewanimation_Uikit Dynamics - Fatal编程技术网

Ios 使用Interface Builder时的UIKitDynamics

Ios 使用Interface Builder时的UIKitDynamics,ios,objective-c,uiviewanimation,uikit-dynamics,Ios,Objective C,Uiviewanimation,Uikit Dynamics,我想使用UIKitDynamics为一些按钮添加动画,但是使用uisnapbehavior进行非常基本的操作根本不起作用。我使用IB来布局我的所有子视图,所以请记住,我不能通过调用self.button.frame来重新定位任何内容,您必须使用约束 这就是我所拥有的…当我运行动画时,它会快速闪烁,看起来很糟糕 // Position the buttons off screen self.swerveButton.translatesAutoresizingMaskIntoCon

我想使用UIKitDynamics为一些按钮添加动画,但是使用uisnapbehavior进行非常基本的操作根本不起作用。我使用IB来布局我的所有子视图,所以请记住,我不能通过调用self.button.frame来重新定位任何内容,您必须使用约束

这就是我所拥有的…当我运行动画时,它会快速闪烁,看起来很糟糕

// Position the buttons off screen
        self.swerveButton.translatesAutoresizingMaskIntoConstraints = NO;
        self.followButton.translatesAutoresizingMaskIntoConstraints = NO;
        self.swerveButtonTopSpaceConstraint.constant = -200;

        CGPoint swerveSnapPoint = self.swerveButton.center;
        CGPoint followSnapPoint = self.followButton.center;

        UISnapBehavior *followSnap = [[UISnapBehavior alloc] initWithItem:self.followButton
                                                              snapToPoint:followSnapPoint];

        UISnapBehavior *swerveSnap = [[UISnapBehavior alloc] initWithItem:self.swerveButton
                                                              snapToPoint:swerveSnapPoint];


        [self.overlayView fadeInWithDuration:0.2 completion:^{
            swerveSnap.damping = 0.3;
            [self.animator addBehavior:swerveSnap];

            followSnap.damping = 0.3;
            [self.animator addBehavior:followSnap];
        }];
    }

UIKitDynamics不适用于约束。如果你想使用它们,你必须老一套地手动设置帧,至少在动画中是这样。

我找到了一个解决办法,如果你创建一个自定义对象作为动态项,你可以在UISNAPBehavior的动作块中更改约束。效果很好。