Last active
August 13, 2020 09:47
-
-
Save santoshrajan/58b399b0b6a7a60a72d4 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
class VerticalLayout: UIView { | |
var yOffsets: [CGFloat] = [] | |
init(width: CGFloat) { | |
super.init(frame: CGRectMake(0, 0, width, 0)) | |
} | |
required init(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
override func layoutSubviews() { | |
var height: CGFloat = 0 | |
for i in 0..<subviews.count { | |
var view = subviews[i] as UIView | |
view.layoutSubviews() | |
height += yOffsets[i] | |
view.frame.origin.y = height | |
height += view.frame.height | |
} | |
self.frame.size.height = height | |
} | |
override func addSubview(view: UIView) { | |
yOffsets.append(view.frame.origin.y) | |
super.addSubview(view) | |
} | |
func removeAll() { | |
for view in subviews { | |
view.removeFromSuperview() | |
} | |
yOffsets.removeAll(keepCapacity: false) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I am using this class for UIscrollview instead of UIview. While scrolling i am getting extra view added and also view getting shake. can u help me