gpt4 book ai didi

ios - 编写一组执行类似操作的轻击手势识别器的最 Eloquent 方式

转载 作者:行者123 更新时间:2023-11-30 13:25:03 25 4
gpt4 key购买 nike

我有 9 个 View ,带有 9 个点击手势识别器,它们都执行非常相似的任务。我绞尽脑汁想用一种更 Eloquent 方式来写这篇文章,但一直想不出任何办法。任何帮助将不胜感激!

func flipToBack(){
let matrix = Animations.HotSpotNumber(rawValue: currentHotSpot)
guard let dict = matrix?.instructions else {return}
flipLayerSecondPhaseWithInstructions(dict, layer: frontView.layer, directionOfTransformation: "towardsBackSide")
}

func flipToFront(){
let matrix = Animations.HotSpotNumber(rawValue: currentHotSpot)
guard let dict = matrix?.instructions else {return}
flipLayerSecondPhaseWithInstructions(dict, layer: frontView.layer, directionOfTransformation: "towardsFrontSide")
}


func handleBackSideTap(){
let animation = Animations.HotSpotNumber(rawValue: currentHotSpot)
guard let dict = animation?.instructions else {return}
flipLayerFirstPhaseWithInstructions(dict, layer: frontView.layer, directionOfTransformation: "towardsFrontSide")
}

func handleHotSpotOneTap(){
let dict = Animations.HotSpotNumber.One.instructions
currentHotSpot = 1
flipLayerFirstPhaseWithInstructions(dict, layer: frontView.layer, directionOfTransformation: "towardsBackSide")
}

func handleHotSpotTwoTap(){
let dict = Animations.HotSpotNumber.Two.instructions
currentHotSpot = 2
flipLayerFirstPhaseWithInstructions(dict, layer: frontView.layer, directionOfTransformation: "towardsBackSide")
}

func handleHotSpotThreeTap(){
let dict = Animations.HotSpotNumber.Three.instructions
currentHotSpot = 3
flipLayerFirstPhaseWithInstructions(dict, layer: frontView.layer, directionOfTransformation: "towardsBackSide")
}

func handleHotSpotFourTap(){
let dict = Animations.HotSpotNumber.Four.instructions
currentHotSpot = 4
flipLayerFirstPhaseWithInstructions(dict, layer: frontView.layer, directionOfTransformation: "towardsBackSide")
}

func handleHotSpotSixTap(){
let dict = Animations.HotSpotNumber.Six.instructions
currentHotSpot = 6
flipLayerFirstPhaseWithInstructions(dict, layer: frontView.layer, directionOfTransformation: "towardsBackSide")

}

func handleHotSpotSevenTap(){
let dict = Animations.HotSpotNumber.Seven.instructions
currentHotSpot = 7
flipLayerFirstPhaseWithInstructions(dict, layer: frontView.layer, directionOfTransformation: "towardsBackSide")
}

func handleHotSpotEightTap(){
let dict = Animations.HotSpotNumber.Eight.instructions
currentHotSpot = 8
flipLayerFirstPhaseWithInstructions(dict, layer: frontView.layer, directionOfTransformation: "towardsBackSide")
}

func handleHotSpotNineTap(){
let dict = Animations.HotSpotNumber.Nine.instructions
currentHotSpot = 9
flipLayerFirstPhaseWithInstructions(dict, layer: frontView.layer, directionOfTransformation: "towardsBackSide")
}

最佳答案

您可以创建一个接受几个参数来指定任务的函数(甚至是扩展)。然后,您无需为每个识别器编写整个函数,只需调用一个识别器并指定任务的参数即可。

关于ios - 编写一组执行类似操作的轻击手势识别器的最 Eloquent 方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37331992/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com