ios - Can I apply the same animation to multiple text fields? -


i'm creating method shakes uitextfield , use pop heavy lifting.

- (void)textfielderroranimation {      popspringanimation *shake = [popspringanimation animationwithpropertynamed:kpoplayerpositionx];      shake.springbounciness = 10;     shake.velocity = @(2000);       [self.value.layer pop_addanimation:shake forkey:@"shakevalue"];     [self.year.layer pop_addanimation:shake forkey:@"shakeyear"]; } 

it seems working when apply animation object "value" not when it's applied "value" , "year" @ same time.

i know can create shake2, shake3 etc 1 each textfield seems strange i'd need that.

any ideas how can reuse animation?

of course can. about, kind of reusing animations creating method returns animation , setting name , key values correctly.

- (popspringanimation *)popshakeanimation {   popspringanimation *shakeanimation = [popspringanimation animationwithpropertynamed:kpoplayerpositionx]; shakeanimation.velocity = @2000; shakeanimation.springbounciness = 20; shakeanimation.name = @"shakeanimation";  return shakeanimation; 

}

and whenever need shake views add them views' layer.

    [self.textfield001.layer pop_addanimation:[self popshakeanimation]                                             forkey:@"shakeanimation"];     [self.textfield002.layer pop_addanimation:[self popshakeanimation]                                             forkey:@"shakeanimation"];     [self.textfield003.layer pop_addanimation:[self popshakeanimation]                                               forkey:@"shakeanimation"]; 

just remember set key values name you've created animation in first place.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -