【发布时间】:2016-05-20 05:36:24
【问题描述】:
因此,我学会了如何在视图中的图片上做出平移手势,并四处移动它。然后我尝试用 TableViewCell 做同样的事情:用平移手势水平移动它,它只是没有反应:
所以我创建了TableViewController.swift,设置了常用的东西以确保它正常运行并显示带有动态表格单元格的数据列表。
代码:
var todoItems = [TodoItem]()
override func viewDidLoad() {
super.viewDidLoad()
createSomeData()
}
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return todoItems.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(constant.cellIdentifier, forIndexPath: indexPath) as! TodoTableViewCell
cell.todoItem = todoItems[indexPath.row]
return cell
}
然后我从调色板中取出Pan Gesture Reconizer,将其放在tableviewcell 上,确保它连接到连接检查器中,然后,ctrl + 将Pan Gesture Reconizer 拖到TableViewController.swift 中:
@IBAction func handlePan(gesture: UIPanGestureRecognizer) {
let transition = gesture.translationInView(self.view)
switch gesture.state{
case .Changed:
if let view = gesture.view {
view.center = CGPoint(x: view.center.x + transition.x, y: view.center.y)
}
gesture.setTranslation(CGPointZero, inView: self.view)
default:break
}
}
它不起作用。为什么?
【问题讨论】:
标签: ios swift uitableview gesture uipangesturerecognizer