2011-07-27 18 views
7

Stworzyłem prostą aplikację z segmentowaną kontrolą u góry. Kiedy klikam jeden z dwóch segmentów kontrolki, UIImageView zaczyna się obracać. Mam przycisk resetowania, aby ustawić jego transformację na CGAffineTransformIdentity.CGAffineTransformIdentity nie resetuje UIImageView po wielu przekształceniach?

Problem występuje, gdy metoda, która wykonuje animację widoku widoku, jest wywoływana po raz drugi, przełączając segmenty w tę iz powrotem. Wpisanie resetowania usuwa tylko ostatnią animację. Muszę zmienić segmenty po raz drugi, aby animacje zatrzymały się po całkowitym zresetowaniu.

Następujący kod jest wywoływany, gdy wybieram segment do obracania UIImageView i oczywiście wywoływany po raz drugi podczas klikania między segmentami.

// Begin the animation block and set its name 
[UIView beginAnimations:@"Rotate Animation" context:nil]; 

// Set the duration of the animation in seconds (floating point value) 
[UIView setAnimationDuration:0.5]; 

// Set the number of times the animation will repeat (NSIntegerMax setting would repeat indefinately) (floating point value) 
[UIView setAnimationRepeatCount:NSIntegerMax]; 

// Set the animation to auto-reverse (complete the animation in one direction and then do it backwards) 
[UIView setAnimationRepeatAutoreverses:YES]; 

// Animation curve dictates the speed over time of an animation (UIViewAnimationCurveEaseIn, UIViewAnimationCurveEaseOut, UIViewAnimationCurveEaseInOut, UIViewAnimationCurveLinear) 
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 

// Changes the imageViews transform property to rotate the view using CGAffineTransformRotate 
// CGAffineTransformRotate(transformToStartFrom, angleToRotateInRadians) 
// Starting transform property can be set to CGAffineTransformIdentity to start from views original transform state 
// This can also be done using CGAffineTransformMakeRotation(angleInRadians) to start from the IdentityTransform without implicitly stating so 
self.imageView.transform = CGAffineTransformRotate(self.imageView.transform, degreesToRadians(90)); 

[UIView commitAnimations]; 

reset Przycisk wywołuje ten kod -

self.imageView.transform = CGAffineTransformIdentity; 

Odpowiedz

6

spróbować tej

[UIView animateWithDuration:0.2 animations:^() { 

    self.imageView.transform = CGAffineTransformIdentity; 



}]; 
+2

Will trwania animacji (0,2 sekundy) doda pożądany efekt? Proszę wyjaśnić niewiele więcej. – HDdeveloper

+0

Zamiast tego można ustawić żądaną wartość, po prostu pokazałem, że ma opcję czasu trwania. Pozdrawiam :) –

+0

Pytania mówią, że on już ustawia CGAffineTransformIdentity i to nie działa – trapper

Powiązane problemy