imageView上に同サイズのbuttonを設置してそれをタップした時に拡大画面を表示することはできるのですが、それだとimageViewの画像を取得できません。
上記はDelegate
パターンで以下の様に実装できます、参考にしてみてください。
※ 最低限のコードなので自分のプロジェクトに読み替えてください。
【Swift】delegate実装の流れ - Qiita
swift
1
2import UIKit
3
4class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, HogeCellDelegate {
5
6 @IBOutlet weak var tableView: UITableView!
7
8 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
9 if let cell = tableView.dequeueReusableCell(withIdentifier: "HogeCell", for: indexPath as IndexPath) as? HogeCell {
10 // Delegateを自分に登録
11 cell.delegate = self
12 return cell
13 }
14 return UITableViewCell()
15 }
16
17 func tappedImage(image: UIImage) {
18 // セルの画像上ボタンタップ時に呼ばれる(画像が引数で渡される)
19 }
20}
21
22// プロトコル定義
23protocol HogeCellDelegate: class {
24 func tappedImage(image: UIImage)
25}
26
27// セル
28class HogeCell: UITableViewCell {
29
30 // Delegate
31 weak var delegate: HogeCellDelegate?
32 // セルに表示している画像
33 @IBOutlet weak var cellImage: UIImageView!
34
35 // 画像上のボタンタップ時イベント
36 @IBAction func tappedImage(_ sender: UIButton) {
37 if let image = cellImage.image {
38 // Delegateメソッドを呼ぶ(引数は渡したい画像)
39 delegate?.tappedImage(image: image)
40 }
41 }
42}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/22 08:30