在我的登录视图中,有一个连续的背景动画和一个用于登录的Facebook按钮。
问题是,当我打开Facebook登录页面(Safari)并关闭它时,动画停止,因为它可以在下面看到:
关注我的动画代码:
//MARK: - View animations
func animateLogin(){
self.animateBackground(imageName: "backgroundLogin-layer1", scrolling: .Left, timing: 30.0)
self.animateBackground(imageName: "backgroundLogin-layer2", scrolling: .Right, timing: 35.0)
self.animateBackground(imageName: "backgroundLogin-layer3", scrolling: .Right, timing: 50.0)
self.animateBackground(imageName: "backgroundLogin-layer4", scrolling: .Right, timing: 60.0)
}
func animateBackground(imageName img: String, scrolling side: Side, timing duration: NSTimeInterval){
let backgroundImage = UIImage(named:img)!
let amountToKeepImageSquare = backgroundImage.size.height - self.view.frame.size.height
let backgroundImageView1 = UIImageView(image: backgroundImage)
backgroundImageView1.frame = CGRect(x: self.view.frame.origin.x, y: self.view.frame.origin.y, width: backgroundImage.size.width - amountToKeepImageSquare, height: self.view.frame.size.height)
self.view.addSubview(backgroundImageView1)
var positionXSecondImage: CGFloat
var multiplier: CGFloat
if side == .Right{
//Scrolling right
positionXSecondImage = (backgroundImageView1.frame.size.width * -1.0)
multiplier = 1
}else{
//Scrolling left
positionXSecondImage = backgroundImageView1.frame.size.width
multiplier = -1
}
let backgroundImageView2 = UIImageView(image: backgroundImage)
backgroundImageView2.frame = CGRect(x: positionXSecondImage, y: self.view.frame.origin.y, width: backgroundImage.size.width - amountToKeepImageSquare, height: self.view.frame.height)
self.view.addSubview(backgroundImageView2)
self.view.sendSubviewToBack(backgroundImageView1)
self.view.sendSubviewToBack(backgroundImageView2)
// Animate background
UIView.animateWithDuration(duration, delay: 0.0, options: [.Repeat, .CurveLinear], animations: {
backgroundImageView1.frame = CGRectOffset(backgroundImageView1.frame, multiplier * backgroundImageView1.frame.size.width, 0.0)
backgroundImageView2.frame = CGRectOffset(backgroundImageView2.frame, multiplier * backgroundImageView2.frame.size.width, 0.0)
}, completion: nil)
}
我在 ViewDidLoad 方法中调用 animateLogin 函数,我已经尝试在 ViewDidAppear
中调用它 //MARK: - App's lifecycle
override func viewDidLoad() {
super.viewDidLoad()
...
...
//Calling function taht makes background animted
self.animateLogin()
...
...
}
我需要在关闭Facebook登录视图后重新启动动画。