·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> app软件开发 >> IOS开发 >> 动画效果

动画效果

作者:佚名      IOS开发编辑:admin      更新时间:2022-07-23

UipushBehavior  推动效果

 typedef NS_ENUM(NSInteger, UIPushBehaviorMode) {

 UIPushBehaviorModeContinuous, 持续的力

 UIPushBehaviorModeInstantaneous 瞬间的力

 } NS_ENUM_AVAILABLE_IOS(7_0);

 @PRoperty (nonatomic, readonly) UIPushBehaviorMode mode; 推动效果的样式

 @property (nonatomic, readwrite) BOOL active; 是否激活

 @property (readwrite, nonatomic) CGFloat angle; 推动角度

 // A continuous force vector with a magnitude of 1.0, applied to a 100 point x 100 point view whose density value is 1.0, results in view acceleration of 100 points per s^2

 @property (readwrite, nonatomic) CGFloat magnitude; 推动力量

 @property (readwrite, nonatomic) CGVector pushDirection; 推动的方向

 

 

 ------------------------------

 UISnapBehavior:迅速移动效果

 // The point argument is expressed in the reference coordinate system

 - (instancetype)initWithItem:(id <UIDynamicItem>)item snapToPoint:(CGPoint)point;

 迅速移动效果 只能一次 添加到一个元素上  snapToPoint 让他移动到哪一个点

 

 @property (nonatomic, assign) CGFloat damping; // damping value from 0.0 to 1.0. 0.0 is the least oscillation. damping 的范围是(0.0-1.0)

 

 UIAttachmentBehavior  符着效果

 typedef NS_ENUM(NSInteger, UIAttachmentBehaviorType) {

 UIAttachmentBehaviorTypeItems, 吸附一个元素

 UIAttachmentBehaviorTypeAnchor 吸附一个点

 } NS_ENUM_AVAILABLE_IOS(7_0);

 设置吸附效果的样式

 @property (readonly, nonatomic) UIAttachmentBehaviorType attachedBehaviorType;

 

 

 UIAttachmentBehavior:附着效果

 吸附着一个视图 或者一个点  (也可以多个连接)

 

 附着效果 一个视图与一个锚点或者另一个视图相连接的情况

 附着行为描述的是两点之间的连接情况,可以模拟刚性或者弹性连接

 在多个物体间设定多个UIAttachmentBehavior,可以模拟多物体连接

 

 typedef NS_ENUM(NSInteger, UIAttachmentBehaviorType) {

 UIAttachmentBehaviorTypeItems, 吸附一个元素

 UIAttachmentBehaviorTypeAnchor 吸附一个点

 } NS_ENUM_AVAILABLE_IOS(7_0);

 设置吸附效果的样式

 @property (readonly, nonatomic) UIAttachmentBehaviorType attachedBehaviorType;

 

 @property (readwrite, nonatomic) CGPoint anchorPoint;锚点

 

 @property (readwrite, nonatomic) CGFloat length;距离 与锚点的距离

 @property (readwrite, nonatomic) CGFloat damping; // 1: critical damping  跳跃度

 @property (readwrite, nonatomic) CGFloat frequency; // in Hertz   幅度

dynamicAnimator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
    view = [[UIView alloc] initWithFrame:CGRectMake(50, 50,50, 50)];
    view.backgroundColor = [UIColor purpleColor];
    [self.view addSubview:view];
    view1 = [[UIView alloc] initWithFrame:CGRectMake(150, 150,50, 50)];
    view1.backgroundColor = [UIColor colorWithRed:0.300 green:0.334 blue:0.768 alpha:1.000];
    [self.view addSubview:view1];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
    [self.view addGestureRecognizer:tap];

  tapAction:方法的实现

- (void)tapAction:(UITapGestureRecognizer *)sender{
#pragma mark 推动效果
/*    [dynamicAnimator removeAllBehaviors];
//    UIPushBehavior *push = [[UIPushBehavior alloc] initWithItems:@[view] mode:UIPushBehaviorModeContinuous];
////    x是正右  负左  y是正下  负上
//    push.pushDirection = CGVectorMake(1, 0);
//    push.magnitude = 5;
//    push.active = YES;
//    [dynamicAnimator addBehavior:push];
//    ------------------------------------*/
#pragma mark 迅速移动效果
/*    [dynamicAnimator removeAllBehaviors];
    UISnapBehavior *snap = [[UISnapBehavior alloc] initWithItem:view snapToPoint:[sender locationInView:self.view]];
    snap.damping = 0;///阻尼值从0.0到1.0。0.0是最低的振荡
    [dynamicAnimator addBehavior:snap];
 ------------------------------------------*/
#pragma mark 吸符效果(吸符一个点)
    [dynamicAnimator removeAllBehaviors];
    UIAttachmentBehavior *attachment = [[UIAttachmentBehavior alloc] initWithItem:view offsetFromCenter:UIOffsetMake(20, 20) attachedToAnchor:[sender locationInView:self.view]];
    attachment.length = 100;
    attachment.damping = 0.5;
    attachment.frequency = 50;
    [dynamicAnimator addBehavior:attachment];
#pragma mark  吸符效果(吸符一个视图)
//    UIAttachmentBehavior *attachment1 = [[UIAttachmentBehavior alloc] initWithItem:view offsetFromCenter:UIOffsetMake(10, 10) attachedToItem:view1 offsetFromCenter:UIOffsetMake(10, 10)];
//    attachment1.length = 100;
//    attachment1.damping = 0.5;
//    attachment1.frequency = 50;
//    [dynamicAnimator addBehavior:attachment1];
    
    UIAttachmentBehavior *attachment2 = [[UIAttachmentBehavior alloc] initWithItem:view1 attachedToItem:view];
    attachment2.damping = 0.5;
    attachment2.frequency = 50;
    [dynamicAnimator addBehavior:attachment2];
    
}