-
Notifications
You must be signed in to change notification settings - Fork 0
/
CostumeCell.swift
85 lines (62 loc) · 2.86 KB
/
CostumeCell.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//
// CostumeCell.swift
// VistaBridge
//
// Created by 齐晴 on 17/1/1.
// Copyright © 2017年 GaryQi. All rights reserved.
//
import UIKit
class CostumeCell: UITableViewCell {
@IBOutlet weak var label_costumeName: UILabel!
@IBOutlet weak var label_costumeSum: UILabel!
@IBOutlet weak var rightView: UIView!
var images : [String] = []
let containerView = UIView()
let NotificationName_ZoomInImage = "NotificationName_ZoomInImage"
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
func prepareScrollViewForImages(_ costumeID : Int){
let refFrame = rightView.frame
let scrFrame = CGRect(x: 20, y: 20, width: refFrame.size.width - 40, height: refFrame.size.height - 50)
let scrView = UIScrollView(frame: scrFrame)
for costume in costumes {
if costume.ID == costumeID {
images = costume.images
}
if images != [] {
var point_x : CGFloat = 0
let point_y : CGFloat = 0
let size_width : CGFloat = 120.0
let size_height = scrView.frame.size.height
let n = images.count
containerView.frame = CGRect(x: 0, y: 0, width: size_width * CGFloat(n), height: size_height)
for imageName in images {
let image = UIImage(named: imageName)
let imageView = UIImageView(image: image)
imageView.frame = CGRect(x: point_x, y: point_y, width: size_width, height: size_height)
//Add GestureRecognizers
imageView.isUserInteractionEnabled = true
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(CostumeCell.imageTaped(_:)))
imageView.addGestureRecognizer(tapGesture)
containerView.addSubview(imageView)
point_x += 120
}
scrView.contentSize = containerView.frame.size
scrView.addSubview(containerView)
}
rightView.addSubview(scrView)
}
}
func imageTaped(_ gesture: UITapGestureRecognizer) {
let point = gesture.location(in: containerView)
let index = Int(point.x/120)
NotificationCenter.default.post(name: Notification.Name(rawValue: NotificationName_ZoomInImage), object: self, userInfo: ["ImageName" : images[index]])
print(images)
}
}