计时器不能正常工作,斯威夫特

时间:2017-08-05 14:13:40

标签: ios swift user-interface timer avfoundation

我正在尝试将计时器计数向上我按住按钮的秒数。(按住录制视频)并且它只是无法正常工作...有时会跳过秒&安培;有时只是冻结,然后加速赶上......我真的需要你的帮助解决这个问题,我需要定时器尽可能流畅和恒定,谢谢。

class A:
    def greet(self, person):
        print('hello', person)

def create_B(___person__):
    class B(A):
        def greet(self):
            super().greet(___person__)
    return B

B = create_B('bob')
B().greet() # prints hello bob

assert [c.cell_contents for c in B.greet.__closure__] == ['bob', B]

btw我在同一时间运行我的自定义AVFoundation相机的VideoPreviewLayer ..可能会导致问题?

2 个答案:

答案 0 :(得分:3)

Timer与用户互动在同一DispatchQueue内工作(例如在UITableView中滚动,点按UIGestureRecognizer或按住UIbutton )。因此,当用户执行任何操作时,Timer将冻结片刻。

您可以使用例如AsyncTimer

来解决此问题

答案 1 :(得分:0)

您可以调用fire()

recordingCounter = Timer.scheduledTimer(withTimeInterval: duration, repeats: true, block: {[unowned self] (timer) in 

}) 

recordingCounter.fire()
相关问题