Last active
July 22, 2020 13:13
-
-
Save TarasShu/7e6809d7457638047de711a52793a79c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var scrollViewVertical = UIScrollView() // внимание | |
var firstView = UIView() | |
let lable = UILabel() | |
var scrollViewVerticalFrame: UIView // и тут | |
func squareVertical(_ count: Int) { | |
var squeres = [UIView]() | |
for i in 0..<count{ | |
let sq = UIView() | |
let height = 200 | |
let color: [UIColor] = [.systemRed, | |
.systemYellow, | |
.systemBlue, | |
.systemGray, | |
.systemPink, | |
.systemGray2, | |
.systemTeal, | |
.systemGreen] | |
sq.frame = CGRect(x: 50 , | |
y: 20 + (( height + 20) * i) , | |
width: 100 , | |
height: height) | |
let endOfBoard: CGFloat = CGFloat(height + (( height + 20) * i) + 35) | |
sq.backgroundColor = Array.randomElement(color)()! | |
squeres.append(sq) | |
scrollViewVertical.contentSize.height = endOfBoard | |
scrollViewVertical.alwaysBounceVertical = true | |
func scrollViewDidScroll(_ scrollView: UIScrollView){ | |
sq.frame = CGRect(x: Int(scrollView.bounds.minX) + 50, | |
y: Int(scrollView.bounds.minY) + 20 + (( height + 20) * i), | |
width: 200, | |
height: height) | |
} | |
scrollViewVerticalFrame = UIView(frame: sq.frame) // Вот тут главный мув // засунул это сюда, потому что sq.frame справедливо только внутри лупы | |
} | |
for i in squeres { | |
i.layer.cornerRadius = 50 | |
scrollViewVertical.addSubview(i) | |
} | |
} | |
override func loadView() { | |
scrollViewVertical = UIView(frame: scrollViewVerticalFrame)// вот тут второй мув // выдает ошибку Cannot convert value of type 'UIView' to expected argument type 'CGRect' | |
// а хотелось бы чтоб работало, как работает внутри лупы | |
// | |
scrollViewVertical.delegate = self | |
scrollViewHorizontal.backgroundColor = .systemGray6 | |
scrollViewVertical.backgroundColor = scrollViewHorizontal.backgroundColor | |
squareHorizontal(5) | |
squareVertical(1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment