2012-04-20 16 views
11

Gölge ve UIImageView alt görünümü içeren bir UIView sahibiyim.UIView öğesinin boyutunu yumuşak bir şekilde döndürme ve değiştirme

iPad döndürüldüğünde görünümü yeniden boyutlandırmak istiyorum ve bunu willRotateToInterfaceOrientation geri aramada yapmaya çalışıyorum.

UIView üzerindeki gölgeyi temel şekilde ayarlarsanız, döndürme çok keskindir; Bu yüzden, gölge ayarı layer.shadowPath öğesinin nasıl ayarlanacağı konusunda bazı önerilerde bulunmak istiyorum.

Çerçeve boyutu değişikliğini [UIView animateWithDuration:animations] kullanarak ve yeni shadowPath'u aynı satırda ayarlamayı denedim, ancak gölge yolu yeni boyuta geçiyor.

Katmanların gölgesini animasyon bloğunda değiştirmezsem, değişmez.

Yaptığım birkaç aramadan, katman özelliklerinde yapılan değişikliklerin bir CABasicAnimation ile yapılması gerekiyor.

Sanırım soru "UIView'in çerçeve boyutunu ve katman değişimini aynı anda nasıl canlandırabilirim?"

cevap

8

İnsanın umduğundan biraz daha fazla kod var ama bunun gibi bir şey işe yaramalı.

CGFloat animationDuration = 5.0; 

    // Create the CABasicAnimation for the shadow 
    CABasicAnimation *shadowAnimation = [CABasicAnimation animationWithKeyPath:@"shadowPath"]; 
    shadowAnimation.duration = animationDuration; 
    shadowAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; // Match the easing of the UIView block animation 
    shadowAnimation.fromValue = (id)self.shadowedView.layer.shadowPath; 

    // Animate the frame change on the view 
    [UIView animateWithDuration:animationDuration 
         delay:0.0f 
         options:UIViewAnimationCurveEaseInOut 
        animations:^{ 
        self.shadowedView.frame = CGRectMake(self.shadowedView.frame.origin.x, 
                  self.shadowedView.frame.origin.y, 
                  self.shadowedView.frame.size.width * 2., 
                  self.shadowedView.frame.size.height * 2); 
        } completion:nil]; 

    // Set the toValue for the animation to the new frame of the view 
    shadowAnimation.toValue = (id)[UIBezierPath bezierPathWithRect:self.shadowedView.bounds].CGPath; 

    // Add the shadow path animation 
    [self.shadowedView.layer addAnimation:shadowAnimation forKey:@"shadowPath"]; 

    // Set the new shadow path 
    self.shadowedView.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.shadowedView.bounds].CGPath; 
İlgili konular