CGAffineTransformIdentity не сбрасывает UIImageView после нескольких преобразований? - PullRequest
8 голосов
/ 27 июля 2011

Я создал простое приложение с сегментированным элементом управления вверху. Когда я нажимаю на один из двух сегментов элемента управления, UIImageView начинает вращаться. У меня есть кнопка сброса, подключенная для установки ее преобразования в CGAffineTransformIdentity.

Проблема возникает, когда метод, который выполняет анимацию вращения вида, вызывается второй раз путем переключения сегментов назад и вперед. Нажатие сброса удаляет только самую последнюю анимацию. Мне нужно переключить сегменты во второй раз, чтобы анимация полностью остановилась.

Следующий код вызывается, когда я выбираю сегмент для поворота UIImageView, и, очевидно, вызывается второй раз, когда я нажимаю между сегментами.

// 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];

Кнопка сброса вызывает этот код -

self.imageView.transform = CGAffineTransformIdentity;

1 Ответ

7 голосов
/ 27 июля 2011

попробуйте

[UIView animateWithDuration:0.2 animations:^() {

    self.imageView.transform = CGAffineTransformIdentity;



}];
...