-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageViewController.swift
102 lines (82 loc) · 3.29 KB
/
ImageViewController.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
// ImageViewController.swift
// AutoLayoutAnimation
//
// Created by Ozgur Vatansever on 11/1/15.
// Copyright © 2015 Techshed. All rights reserved.
//
import UIKit
import Cartography
class ImageViewController: UIViewController {
var firstImageView: UIImageView!
var secondImageView: UIImageView!
var thirdImageView: UIImageView!
var scrollView: UIScrollView!
var textField: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
edgesForExtendedLayout = UIRectEdge()
view.backgroundColor = .white
title = "Scaling"
print("Ozgur".length)
scrollView = UIScrollView(frame: CGRect.zero)
view.addSubview(scrollView)
constrain(scrollView, v2: view) { scrollView, view in
scrollView.leading == view.leading
scrollView.trailing == view.trailing
scrollView.top == view.top
scrollView.bottom == view.bottom
}
let image = UIImage(named: "[email protected]")!
firstImageView = UIImageView(image: image)
firstImageView.backgroundColor = .clear
secondImageView = UIImageView(
image: UIImage(image: image, scaleAspectFitTo: CGSize(width: 283.375, height: 201.0))
)
secondImageView.contentMode = .center
secondImageView.backgroundColor = .clear
thirdImageView = UIImageView(
image: UIImage(image: image, scaleAspectFillTo: CGSize(width: 283.375, height: 150.0))
)
thirdImageView.contentMode = .center
thirdImageView.backgroundColor = .clear
scrollView.translatesAutoresizingMaskIntoConstraints = false
firstImageView.translatesAutoresizingMaskIntoConstraints = false
secondImageView.translatesAutoresizingMaskIntoConstraints = false
thirdImageView.translatesAutoresizingMaskIntoConstraints = false
scrollView.addSubview(firstImageView)
scrollView.addSubview(secondImageView)
scrollView.addSubview(thirdImageView)
constrain(firstImageView, v2: secondImageView, v3: scrollView) { firstImageView, secondImageView, scrollView in
firstImageView.top == scrollView.top + 9.0
firstImageView.centerX == scrollView.centerX
firstImageView.width == 283.375
firstImageView.height == 201.0
secondImageView.top == firstImageView.bottom + 9.0
secondImageView.centerX == firstImageView.centerX
secondImageView.width == 283.375
secondImageView.height == 201.0
}
constrain(thirdImageView, v2: secondImageView, v3: scrollView) { thirdImageView, secondImageView, scrollView in
thirdImageView.top == secondImageView.bottom + 9.0
thirdImageView.centerX == secondImageView.centerX
thirdImageView.width == 283.375
thirdImageView.height == 150.0
}
textField = UITextField(frame: CGRect.zero)
textField.borderStyle = .roundedRect
textField.translatesAutoresizingMaskIntoConstraints = false
textField.text = "aaaa"
scrollView.addSubview(textField)
constrain(textField, v2: thirdImageView, v3: scrollView) { textField, thirdImageView, scrollView in
textField.top == thirdImageView.bottom + 9.0
textField.centerX == scrollView.centerX
textField.width == 283.375
textField.height == 50.0
textField.bottom == scrollView.bottom - 9.0
}
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
}
}