Ipad Swift:重置视图的计时器

Ipad Swift:重置视图的计时器,ipad,swift,timer,constraints,reload,Ipad,Swift,Timer,Constraints,Reload,因此,我有一个标签,使用NSTimer每秒计数1。我制作了一个应用程序,它有几个移动的UIImages。但是,每当计时器向上计数一次时,视图似乎会重新加载,UIImages会回到其原始位置。此外,UIImages不是我在故事板中放置它们的位置(我将它们放置在视图之外,以便它们可以向内移动,但当我启动应用程序时,它只是在那里显示它们。它们移动了一秒钟,然后回到原来的位置)。同样的代码在iPhone上运行良好,但在iPad上不起作用。我认为这与约束有关,因为代码是相同的。以下是计时器代码: fun

因此,我有一个标签,使用
NSTimer
每秒计数1。我制作了一个应用程序,它有几个移动的
UIImage
s。但是,每当计时器向上计数一次时,视图似乎会重新加载,
UIImage
s会回到其原始位置。此外,
UIImage
s不是我在故事板中放置它们的位置(我将它们放置在视图之外,以便它们可以向内移动,但当我启动应用程序时,它只是在那里显示它们。它们移动了一秒钟,然后回到原来的位置)。同样的代码在iPhone上运行良好,但在iPad上不起作用。我认为这与约束有关,因为代码是相同的。以下是计时器代码:

 func counting() {

    timerCount = timerCount + 1
    timerLabel.text = "\(timerCount)"


}


override func viewDidLoad() {

    super.viewDidLoad()

    timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("counting"), userInfo: nil, repeats: true)

    // Do any additional setup after loading the view, typically from a override nib.
}
以下是移动我的UIImage的代码:

func MoveWalls() {


    FirstTimer = NSTimer.scheduledTimerWithTimeInterval(0.07, target: self, selector: Selector("FirstMoving"), userInfo: nil, repeats: true)

    SecondTimer = NSTimer.scheduledTimerWithTimeInterval(0.007, target: self, selector:
        Selector("SecondMoving"), userInfo: nil, repeats:true)

    ThirdTimer = NSTimer.scheduledTimerWithTimeInterval(0.006, target: self, selector:
        Selector("ThirdMoving"), userInfo: nil, repeats:true)

    FourthTimer = NSTimer.scheduledTimerWithTimeInterval(0.005, target: self, selector:
        Selector("FourthMoving"), userInfo: nil, repeats:true)
}

func FirstMoving() {
    First.center = CGPointMake(First.center.x + 1, First.center.y)
    }
func SecondMoving() {
    Second.center = CGPointMake(Second.center.x - 1, Second.center.y)
    }
func ThirdMoving() {
    ThirdMoving.center = CGPointMake(Third.center.x, Third.center.y + 1)
    }
func FourthMoving() {
    Fourth.center = CGPointMake(Fourth.center.x, Fourth.center.y  1)
    }
我的限制:

开始和结束游戏的两个按钮(水平居中)

这四幅图像(大小比)


一个计时器(左上角),由于某种原因,它会在每次计数时重置视图

我也有同样的问题。我通过为每个可移动视图添加以下代码来解决此问题:

override func viewDidLoad() {
    super.viewDidLoad()
    self.imageView.translatesAutoresizingMaskIntoConstraints = true
    self.imageView2.translatesAutoresizingMaskIntoConstraints = true
}

我们应该如何帮助您获得关于代码的如此有限的信息?您在哪里绘制/移动图像?您的控件具有哪些自动布局约束?