gpt4 book ai didi

ios - 通过滑动操作更改 UIImageView 图像

转载 作者:行者123 更新时间:2023-11-29 00:58:11 25 4
gpt4 key购买 nike

在我的 tableview 上有一个 UIImageView,我需要在执行滑动操作时更改图像。我有一个 tableview 行的类,所以我更改了代码来尝试这样做。这是代码,但没有用。我该怎么做?

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) -> CellTableViewFriends{  
// you need to implement this method too or you can't swipe to display the actions
let cell = self.tableViewFriends.dequeueReusableCellWithIdentifier("CellTableViewFriends") as! CellTableViewFriends;
cell.imgArrow.image = UIImage(named: "myImage")

return cell
}

最佳答案

在您的单元类中,您可以添加以下方法:

func addSwipeGesture() {
let gestureRecognizer = UISwipeGestureRecognizer(target: self, action: #selector(self.swipedLeft))
gestureRecognizer.direction = .Left
self.addGestureRecognizer(gestureRecognizer)
}

func swipedLeft(gesture: UIGestureRecognizer!) {
//Change picture here
imgArrow.image = UIImage(named: "myImage")
}

您可以更改方向或执行相同的操作来添加多个方向。

然后您应该确保在创建单元格时调用 addSwipeGesture 命令,您可以在 cellForRowAtIndexPath 中执行此操作。

希望这对您有所帮助!

关于ios - 通过滑动操作更改 UIImageView 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37391294/

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