2013-10-08 15 views
15

Próbuję animowanie przycisk niestandardowy korzystając CGAffineTransformMakeScale następująco:Animacja Rozwijaj/Zmniejszenie iOS Rozmiar ImageView

if (stateButton == 0) { //The button is gonna appear 

    self.selected = YES; 

    self.imageView.transform = CGAffineTransformMakeScale(0.01, 0.01); 

    [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ 
     // animate it to the identity transform (100% scale) 
     self.imageView.transform = CGAffineTransformIdentity; 
    } completion:nil]; 

} 
else if (stateButton ==1) { //The button is gonna disappear 


    self.imageView.transform = CGAffineTransformMakeScale(1, 1); 

    [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{ 
     // decrease button 
     self.imageView.transform = CGAffineTransformMakeScale(.01, .01); 
    } completion:^(BOOL finished){ 

     self.selected = NO; 
    }]; 
} 

Przycisk rośnie idealnie do pierwotnego rozmiaru, jednak nie wiem, ale powód kiedy klikam przycisk, aby go zmniejszyć, zmniejsza się on od rozmiaru podobnego do 100% większego niż rozmiar oryginalny do pierwotnego rozmiaru, zamiast zaczynać zmniejszanie rozmiaru oryginału i osiągnąć skalę 0.01, jak wskazałem w kodzie.

Proszę o pomoc!

Odpowiedz

25

można animować rosnąć i maleć rozmiaru widoku obrazu przy użyciu następującego kodu

[UIView animateWithDuration:2.0 animations:^{ 
    self.imageView.transform = CGAffineTransformMakeScale(0.5, 0.5); 
} 
completion:^(BOOL finished){ 
    [UIView animateWithDuration:2.0 animations:^{ 
     self.imageView.transform = CGAffineTransformMakeScale(1, 1);  
    }]; 
}]; 

Spowoduje to spadek ImageView wielkości początkowo a gdy animacja jest skończona będzie wrócić do swojego pierwotnego rozmiaru z animacja.

+0

Niesamowite drogi !!! –

6

SWIFT 3 Wersja

UIView.animate(withDuration: 2.0, animations: {() -> Void in 
    self.imageView?.transform = CGAffineTransform(scaleX: 0.5, y: 0.5) 
}, completion: {(_ finished: Bool) -> Void in 
    UIView.animate(withDuration: 2.0, animations: {() -> Void in 
     self.imageView?.transform = CGAffineTransform(scaleX: 1, y: 1) 
    }) 
}) 
Powiązane problemy