Итак, я узнал, как сделать жест панорамы на картинке, перемещая ее. Затем я пытаюсь сделать то же самое с TableViewCell: перемещая его по горизонтали с помощью жесты панорамы, он просто не реагирует:Попытка применить жест жесткирования к UITableViewCell, но не удалось, почему?
Итак, я создал 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
}
}
Это Безразлично» т работы. Зачем?