2016-03-24 27 views
0

Saat yönünde 360 ​​derece bir düğme oluşturun ve ardından animasyonu 360 saatin tersi yönde tersine çevirin. Fakat animasyon ... Animasyon her zaman 360 saat yönünde.Animate düğmesi 360 saat yönünde ve geri geri

func animateShowingOfMenu(){ 

     let angle = CGFloat(180 * M_PI/180) 
     UIView.animateWithDuration(0.4 
      , animations: {() -> Void in 

       self.blurView.hidden=false 
       self.menuBtn.transform = CGAffineTransformMakeRotation(angle) 
       self.menuBtn.transform = CGAffineTransformMakeRotation(0) 


      }) { (completion) -> Void in 

       print("compeleted") 
     } 

    } 

    func animateHidingOfMenu(){ 

     let angle = CGFloat(-180 * M_PI/180) 
     UIView.animateWithDuration(0.4 
      , animations: {() -> Void in 

       self.blurView.hidden = true 
       self.menuBtn.transform = CGAffineTransformMakeRotation(angle) 
       self.menuBtn.transform = CGAffineTransformMakeRotation(0) 


      }) { (completion) -> Void in 

     } 
    } 

cevap

6

Basit ortak çözüm Sen Diyelim ki (burada self.imageV olarak adlandırılır) bir imageView döndürmek istediğinizi varsayalım için herşeyi

//Clock-wise 
rotateAnyView(makeOrderButton, fromValue: 0, toValue: 2.0 * M_PI, duration: 1) 

//Reverse 
rotateAnyView(makeOrderButton, fromValue: 2.0 * M_PI, toValue:0, duration: 1) 

func rotateAnyView(view: UIView, fromValue: Double, toValue: Float, duration: Double = 1) { 
    let animation = CABasicAnimation(keyPath: "transform.rotation") 
    animation.duration = duration 
    animation.fromValue = formValue 
    animation.toValue = toValue 
    view.layer.addAnimation(animation, forKey: nil) 
} 
0
Objective-C

PFB cevap:

CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"]; 
animation.duration = 1; 
animation.fromValue = [NSNumber numberWithFloat:0]; 
animation.toValue = [NSNumber numberWithFloat:2 * M_PI]; 
animation.autoreverses = YES ; 
[self.containerView.layer addAnimation:animation forKey:nil]; 

tadını çıkarın! rotasyon kısa yönde

yapılır:

0
self.menuBtn.transform = CGAffineTransformMakeRotation(CGFloat(-90 * M_PI/180)) 
self.menuBtn.transform = CGAffineTransformMakeRotation(CGFloat(M_PI) 
self.menuBtn.transform = CGAffineTransformMakeRotation(CGFloat(90 * M_PI/180)) 
self.menuBtn.transform = CGAffineTransformMakeRotation(CGFloat(0) 

bu benim varsayımdır. 180 her iki yönden de aynı olduğu için, her zaman saat yönünde döner. Bu yüzden saat yönünün tersine 90 derece kullanarak bir yön veriyoruz. Swift

üzerinde

0
UIView.animateKeyframesWithDuration(1.0, delay: 0, options: [.Repeat], animations: { 
      UIView.addKeyframeWithRelativeStartTime(0, relativeDuration: 0.25, animations: { 
       self.imageV.transform = CGAffineTransformMakeRotation(90.0 * CGFloat(M_PI)/180.0) 
      }) 
      UIView.addKeyframeWithRelativeStartTime(0.25, relativeDuration: 0.25, animations: { 
       self.imageV.transform = CGAffineTransformMakeRotation(180.0 * CGFloat(M_PI)/180.0) 
      }) 
      UIView.addKeyframeWithRelativeStartTime(0.50, relativeDuration: 0.25, animations: { 
       self.imageV.transform = CGAffineTransformMakeRotation(270.0 * CGFloat(M_PI)/180.0) 
      }) 
      UIView.addKeyframeWithRelativeStartTime(0.75, relativeDuration: 0.25, animations: { 
       self.imageV.transform = CGAffineTransformMakeRotation(360.0 * CGFloat(M_PI)/180.0) 
      }) 

      }, completion: nil) 
+0

döndürebilir. Seçenekler .repeat içerdiğinden, sonsuza kadar tekrarlanmaya devam edecektir. –

İlgili konular