一旦执行就停止performseguewithidentifier

时间:2016-04-18 08:50:04

标签: ios swift uiview ibeacon

我有这个代码用信标更新距离。

func updateDistance(distance: CLProximity) {
    UIView.animateWithDuration(0.8) {
        switch distance {
        case .Unknown:
            print("unknown")
        case .Far:
            print("far")
        case .Near:
            print("near")
        case .Immediate:
             print("Immediate")
             self.performSegueWithIdentifier("beaconSegue", sender: self)
        }
    }
}

我想询问一下如何在已执行的情况下停止self.performSegueWithIdentifier函数。

2 个答案:

答案 0 :(得分:1)

如果您想阻止performSegueWithIdentifier,可以这样做:

override func shouldPerformSegueWithIdentifier(identifier: String,sender: AnyObject?) -> Bool {
    if ... { // Set the condition if you want it can be perform
        return true
    } else {
        return false
    }
}

答案 1 :(得分:0)

首次执行segue时设置一个标志。像这样:

var seguePerformed = false

func updateDistance(distance: CLProximity) {
    UIView.animateWithDuration(0.8) {
        switch distance {
        case .Unknown:
            print("unknown")
        case .Far:
            print("far")
        case .Near:
            print("near")
        case .Immediate:
             print("Immediate")
             if !self.seguePerformed {
                 self.seguePerformed = true
                 self.performSegueWithIdentifier("beaconSegue", sender: self)
             }
        }
    }
}