LoginSignup
14

More than 5 years have passed since last update.

Swift2.2TableView(+Animation)のコードをSwift3.0に対応しためも

Posted at

はじめに

TableViewのアニメーションの勉強にSwift3.0の勉強も兼ねて
以下のeKushidaさんの記事の実装を
Swift3.0でやってみました。
「Yo.」みたいなUITableViewのアニメーションを作る

Swift3.0対応として修正した箇所について自分用メモとして残します。

Swift3対応として修正したところ

TableViewCellのサブタイトル

Swift2.2

UITableViewCell(style: UITableViewCellStyle.Subtitle, reuseIdentifier: "Cell")

Swift3.0

UITableViewCell(style: UITableViewCellStyle.subtitle, reuseIdentifier: "Cell")

TableViewCell選択時のデリゲートメソッド

Swift2.2

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)

Swift3.0

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)

UIView.animate

Swift2.2

UIView.animateWithDuration(0.75, animations: {[weak self] () -> Void in

Swift3.0

UIView.animate(withDuration: 0.75, animations: {[weak self] () -> Void in

CGAffineTransform

Swift2.2

CGAffineTransformMakeTranslation(0, CGFloat(index))

Swift3.0

CGAffineTransform(translationX: 0, y: CGFloat(index))

Arrayのremove

Swift2.2

itemLists.removeAtIndex(indexPath.row)

Swift3.0

itemLists.remove(at: indexPath.row)

TableViewのdeleteRows

Swift2.2

tableView.deleteRowsAtIndexPaths(deleteIndexPaths, withRowAnimation: UITableViewRowAnimation.Bottom)

Swift3.0

tableView.deleteRows(at: deleteIndexPaths, with: UITableViewRowAnimation.bottom)

Arrayのinsert

Swift2.2

itemLists.insert(text, atIndex: 0)

Swift3.0

itemLists.insert(text, at: 0)

Arrayのappend

Swift2.2

insertIndexPaths.append(NSIndexPath(forRow: 0, inSection: 0))

Swift3.0

insertIndexPaths.append(IndexPath(row: 0, section: 0))

TableViewのinsertRows

Swift2.2

tableView.insertRowsAtIndexPaths(insertIndexPaths, withRowAnimation: UITableViewRowAnimation.Top)

Swift3.0

tableView.insertRows(at: insertIndexPaths, with: UITableViewRowAnimation.top)

CGSize

Swift2.2

snapshot.layer.shadowOffset = CGSizeMake(-5, 0)

Swift3.0

snapshot.layer.shadowOffset = CGSize(width: -5, height: 0)

その他

  • "NS"が無くなったり。
  • メソッドの第一引数の扱いが変わったり。(第二以降の引数と扱いが同様になった)
  • enumが小文字始まりになったり。

(上に例アリ)

さいごに

実装した順にひたすら書き連ねていったので、記載順がテキトーになってしまいました。
グループ分けしたほうが見やすかったかも。

Animation実装したTableViewのサンプルは、
整理したらGitHubにあげようかなーと思います。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14