这是最奇怪的事情,当我在xcode上的任何模拟器中运行我的应用程序时,它正常运行,除非我尝试在iphone 4s模拟器和iphone 5模拟器中运行它时表现得很有趣。所以在下面的函数中我是动画发生的地方。我的意思是,通常这些动画运行顺畅,你可以看到我创建的点逐渐在屏幕上移动,但在iphone 4s和5模拟器中,你根本看不到动画,或者你只看到非常简短的闪光其中我不知道为什么。请帮忙!!
func go(){
// Remove add banner from view
self.gameAdBanner?.hidden = true
// Enable the user interaction of the content view
self.contentView.userInteractionEnabled = true
// Make the level label appear
UIView.animateWithDuration(0, delay: 1, options: nil, animations: {
self.levelLabel.alpha = 1
self.levelNumber.alpha = 1
}, completion: {finished in self.displayAd()})
// Declare delay counter varriables
var delayCounter:Int = 100000
var durationCounter:Double = 0
// Initiate the starting level
levelNumber.text = String(level)
// Set up random number varriable that will make the amount of dots in each color very from one color to another
var diversifyRedDots = arc4random_uniform(5)
var diversifyBlueDots = arc4random_uniform(5)
var diversifyYellowDots = arc4random_uniform(5)
var diversifyGreenDots = arc4random_uniform(5)
// Create if statement for first 2 levels so dots always spawn
if level < 3 {
diversifyRedDots = 4
}
// LOOP------------------
for loop in 0...loopNumber {
// set up some constants for the animations
let redDelay = NSTimeInterval(arc4random_uniform(100000) + delayCounter) / 30000
let blueDelay = NSTimeInterval(arc4random_uniform(100000) + delayCounter) / 30000
let yellowDelay = NSTimeInterval(arc4random_uniform(100000) + delayCounter) / 30000
let greenDelay = NSTimeInterval(arc4random_uniform(100000) + delayCounter) / 30000
let options = UIViewAnimationOptions.AllowUserInteraction | UIViewAnimationOptions.LayoutSubviews
//set up some constants for the dots
let redSize:CGFloat = 54
let redYPosition : CGFloat = CGFloat( arc4random_uniform(150)) + 54
let blueSize:CGFloat = 54
let blueYPosition : CGFloat = CGFloat( arc4random_uniform(150)) + 54
let yellowSize:CGFloat = 54
let yellowYPosition : CGFloat = CGFloat( arc4random_uniform(150)) + 54
let greenSize:CGFloat = 54
let greenYPosition : CGFloat = CGFloat( arc4random_uniform(150)) + 54
// create the dots and add them to the view
let redDot = UIButton()
redDot.setBackgroundImage(RedDot, forState: UIControlState.Normal)
redDot.frame = CGRectMake(-100, redYPosition, redSize, redSize)
self.contentView.addSubview(redDot)
let blueDot = UIButton()
blueDot.setBackgroundImage(BlueDot, forState: UIControlState.Normal)
blueDot.frame = CGRectMake(-100, blueYPosition, blueSize, blueSize)
self.contentView.addSubview(blueDot)
let yellowDot = UIButton()
yellowDot.setBackgroundImage(YellowDot, forState: UIControlState.Normal)
yellowDot.frame = CGRectMake(-100, yellowYPosition, yellowSize, yellowSize)
self.contentView.addSubview(yellowDot)
let greenDot = UIButton()
greenDot.setBackgroundImage(GreenDot, forState: UIControlState.Normal)
greenDot.frame = CGRectMake(-100, greenYPosition, greenSize, greenSize)
self.contentView.addSubview(greenDot)
// DEFINE THE ANIMATIONS
// Red
if diversifyRedDots > 5 {
// Increase actual red
self.increaseRed()
// Increase count dot number
UIView.animateWithDuration(dotDuration , delay: redDelay - 6, options: options, animations: {
redDot.frame = CGRectMake(700, redYPosition, redSize, redSize)
}, completion: {finished in redDot.removeFromSuperview()})
}
// Blue
if diversifyBlueDots > 5 {
// Increase actual blue
self.increaseBlue()
// Increase count dot number
UIView.animateWithDuration(dotDuration , delay: blueDelay - 6, options: options, animations: {
blueDot.frame = CGRectMake(700, blueYPosition, blueSize, blueSize)
}, completion: {finished in blueDot.removeFromSuperview()})
}
// Yellow
if diversifyYellowDots > 5 {
// Increase actual yellow
self.increaseYellow()
// Increase count dot number
UIView.animateWithDuration(dotDuration , delay: yellowDelay - 6, options: options, animations: {
yellowDot.frame = CGRectMake(700, yellowYPosition, yellowSize, yellowSize)
}, completion: {finished in yellowDot.removeFromSuperview()})
}
// Green
if diversifyGreenDots > 5 {
// Increae acutual green
self.increaseGreen()
// Increase count dot number
UIView.animateWithDuration(dotDuration , delay: greenDelay - 6, options: options, animations: {
greenDot.frame = CGRectMake(700, greenYPosition, greenSize, greenSize)
}, completion: {finished in greenDot.removeFromSuperview()})
}
// Incremint counters
delayCounter+=50000
diversifyRedDots++
diversifyBlueDots++
diversifyYellowDots++
diversifyGreenDots++
}