2017-02-24 133 views
0

我想旋转一个ImageView和哪个工作,但是当我从另一个屏幕上加载该屏幕动画不起作用。动画不起作用?

class LoadingRequestViewController: UIViewController ,UICollectionViewDelegate,GMSMapViewDelegate, CLLocationManagerDelegate { 
//UI OutletControls 
@IBOutlet weak var loadingImg: UIImageView! 
@IBOutlet var mapView: GMSMapView! 
@IBOutlet weak var containerView: UIView! 
//UI OutletControls 


override func viewDidLoad() { 
    super.viewDidLoad() 

    loadingImg.startRotating() 

} 



func TimerStoppedTrue() { 
    TimerStopped = true 
    NSLog("TimerStopped\(TimerStopped)") 
} 

@IBAction func CancelHireAction(sender: AnyObject) { 
    self.timer.invalidate() 
    self.CancelHire(self.HireID) 
} 

}

extension UIView { 
func startRotating(duration: Double = 1) { 
    let kAnimationKey = "rotation" 

    if self.layer.animationForKey(kAnimationKey) == nil { 
     let animate = CABasicAnimation(keyPath: "transform.rotation") 
     animate.duration = duration 
     animate.repeatCount = Float.infinity 
     animate.fromValue = 0.0 
     animate.toValue = Float(M_PI * 2.0) 
     self.layer.addAnimation(animate, forKey: kAnimationKey) 
    } 


} 
func stopRotating() { 
    let kAnimationKey = "rotation" 

    if self.layer.animationForKey(kAnimationKey) != nil { 
     self.layer.removeAnimationForKey(kAnimationKey) 
    } 
} 

}

当我打电话LoadingRequestViewController像下面的动画不work.But单独它的工作。

let storyboard = UIStoryboard(name: "Main", bundle: nil) 
    let vc = storyboard.instantiateViewControllerWithIdentifier("LoadingSTBID") as! LoadingRequestViewController 

    self.presentViewController(vc, animated: true, completion: nil) 

回答

0

尝试添加它在viewwillAppear。它应该工作得很好!