簡體   English   中英

Xcode 在執行下一個任務之前等待動畫完成

[英]Xcode wait for animation to finish before executing next task

我有一個層,當我向上滑動時向上移動,然后當我向下滑動時同一層向下移動。

當我向上滑動時,我不希望用戶能夠向下滑動以激活該動畫,直到向上滑動動畫完成,反之亦然。

我該如何實現? 我試過使用“isEnabled”禁用滑動手勢,但沒有使用骰子。 其他一些類似問題的答案來自很久以前,並且語法非常不同。 我正在使用最新版本的 xcode。

我對 xcode 比較陌生,所以請原諒我缺乏這方面的信息。 如果您有問題,請告訴我。

謝謝!

這個問題可以通過添加布爾變量、IF 語句以及 DispatchQueue 函數來解決,以防止在當前動畫完成之前發生另一個動畫。

請參閱下面的內容,如果這有幫助,請點贊 :)

import UIKit
var animation_active = false
let animation_duration = 2 //For easy maintenance

func swipe_down() {
    if animation_active == false {
        animation_active == true
        //Animation code goes here. Variable 'animation_active' should be used when performing the animation for easy matinence
        DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(animation_duration), execute: {
            animation_active = false
        })
    }
}


func swipe_up() { //This is exactly the same as swipe_up. Yet it will prevent the swipe animation from occuring when the swipe down animation is occuruing thanks to the variable 'animation_active'
    if animation_active == false {
        animation_active == true
        //Animation code goes here. Variable 'animation_active' should be used when performing the animation for easy matinence
        DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(animation_duration), execute: {
            animation_active = false
        })
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM