Should I remove the Behavior UIPushBehavior - I add a lot of clicks

I have a small UIView that bounces in a drawer. I am adding Instant mode . Push. In fact, I add a lot of clicks - 5 or more Hz.

Mystery:

(1) Do I have removeBehavior ???? if so .. when ?!? "after" "instant"?

(2) Is it that UIPushBehaviorModeInstantaneous is a special case and you do not need (or cannot) delete these files?

(3) When you add Behavior: is it ... holding on ?! UIPushBehavior? Or?? WTF ?!

(4) It seems I could not find these aspects anywhere!

-(void)pushMeRight:(CGFloat)mag
    {
    if ( self.bounceAnimator == nil ) return;
    NSLog(@"...........push me right %.2f", mag);

    UIPushBehavior *pushRight = [[UIPushBehavior alloc]
            initWithItems:@[self]
            mode:UIPushBehaviorModeInstantaneous];

    pushRight.magnitude = mag;
    pushRight.angle = radians(0);   // (NB, 0 is right, 90 is down)
    [self.bounceAnimator addBehavior:pushRight];
    }

{. UIPushBehavior , . : " " , . , , .}


, Rob "" , .action, .

, , , "" , . :/

-(void)pushAllUp:(CGFloat)mag
    {
    if ( self.bounceAnimator == nil ) return;
    for ( UIView *pushme in self.subviews )
        {
        UIPushBehavior *pp =
        [[UIPushBehavior alloc]initWithItems:@[ pushme ]
             mode:UIPushBehaviorModeInstantaneous];

        pp.magnitude = mag;
        pp.angle = radians(270); // (NB, 0 is right, 90 is down)

        UIPushBehavior __weak *weakPP = pp;
        pp.action = ^{ if (!weakPP.active)
             [self.bounceAnimator removeBehavior:weakPP];};

        [self.bounceAnimator addBehavior:pp];
        }
    }
+2
1

:

  • , , UIPushBehavior .

  • removeBehavior , active , .

    , , , -t22 > . ( , behaviors, , .) , , active , , , , .

    (, UISnapBehavior), active, , push , .

  • "" , , , active NO.

  • , , , .

. , , - :

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
    [self.animator removeBehavior:push];
});

action, .

UIPushBehavior *push = [[UIPushBehavior alloc] initWithItems:self.items mode:UIPushBehaviorModeInstantaneous];
push.pushDirection = ...

UIPushBehavior __weak *weakPush = push;  // avoid strong reference cycle
push.action = ^{
    if (!weakPush.active) {
        [self.animator removeBehavior:weakPush];
    }
};

[self.animator addBehavior:push];
+6

All Articles