gpt4 book ai didi

swift - 如何快速在两个 View 上使用滑动手势

转载 作者:行者123 更新时间:2023-11-28 12:47:10 24 4
gpt4 key购买 nike

当我在模拟器上的任何地方从右向左交换时,它正在交换,但我只想在绿色 View 上交换。 我试过这个..

class ViewController: UIViewController {

@IBOutlet weak var red: UIView!
@IBOutlet weak var green: UIView!

override func viewDidLoad() {
super.viewDidLoad()


var sswipe = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:"))
sswipe.direction = .Left
view.addGestureRecognizer(sswipe)

var srwipe = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:"))
srwipe.direction = .Right
view.addGestureRecognizer(srwipe)

}

func handleSwipes(sender:UISwipeGestureRecognizer) {
if(sender.direction == .Left) {
var labelPosition = CGPointMake(self.view.frame.origin.x - 100.0, self.view.frame.origin.y)
self.view.frame = CGRectMake(labelPosition.x , labelPosition.y , self.view.frame.size.width, self.view.frame.size.height)
}
if(sender.direction == .Right) {
var labelPosition = CGPointMake(self.view.frame.origin.x + 100.0, self.view.frame.origin.y)
self.view.frame = CGRectMake(labelPosition.x , labelPosition.y , self.view.frame.size.width, self.view.frame.size.height);
}
}

最佳答案

你正在将你的手势添加到主视图,你需要将它添加到所需的 View 中,在你的情况下它是绿色的,所以它应该是

green.addGestureRecognizer(sswipe)

关于swift - 如何快速在两个 View 上使用滑动手势,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37695383/

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