2011-07-27 18 views
7

Üst kısımda bölümlere ayrılmış bir denetim içeren basit bir uygulama oluşturdum. Kontrolün iki segmentinden birini tıkladığımda bir UIImageView dönmeye başlar. Dönüşümünü CGAffineTransformIdentity olarak ayarlamak için bir sıfırlama düğmem var.CGAffineTransformIntentity, birden çok dönüşümden sonra bir UIImageView'ı sıfırlamıyor mu?

Görünüm döndürme animasyonu yapan yöntem, ileri ve geri bölümler arasında geçiş yaparak ikinci kez çağrıldığında sorun oluşur. İsabet sıfırlama sadece en son animasyonları kaldırır. Animasyonları tamamen sıfırlayarak durması için segmentleri ikinci kez değiştirmem gerekiyor.

UIImageView öğesini döndürmek için segmenti seçtiğimde ve bölümler arasında tıklattığımda açıkça ikinci kez çağrıldığında, aşağıdaki kod çağrılır.

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

sıfırlama düğmesi çağrıları bu kod

-

self.imageView.transform = CGAffineTransformIdentity; 

cevap

6

bu

[UIView animateWithDuration:0.2 animations:^() { 

    self.imageView.transform = CGAffineTransformIdentity; 



}]; 
+2

Will animasyon süresini (0.2 saniye) deneyin istenen etkiyi katacak? Lütfen biraz daha açıkla .. – HDdeveloper

+0

İstediğiniz değeri ayarlayabilirsiniz, sadece süre seçeneğinin olduğunu gösterdim. Şerefe :) –

+0

Sorular şu anda CGAffineTransformIdentity ayarlandığını ve işe yaramadığını söylüyor – trapper

İlgili konular