Reputation: 552
Why does my UIView
got different position on different iPhone screen sizes ? I guess it's because of autoresizingMask
but how could I get a frame of a view after applying autoresizingMask
, to create some universal logic? or whats the best practice to handle this ?
here is the code :
private func setup() {
positionView = CircularProjectPositionControl(frame: self.bounds)
positionView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
positionView.outerCircleWidth = outerCircleWidth
assetsView = CircularProjectAssetsControl(frame: self.bounds)
assetsView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
assetsView.backgroundColor = UIColor.clearColor()
assetsView.imageWidth = outerCircleWidth
let size = CGSize(width:40, height:40)
let width = floor(CGRectGetMidX(self.bounds) - size.width/2.0)
let height = floor(CGRectGetMidY(self.bounds) - size.width/2.0)
collaboratorView = AvatarView(frame: CGRect(x: width, y: height, width: size.width, height: size.height))
collaboratorView.autoresizingMask = [.FlexibleBottomMargin, .FlexibleLeftMargin, .FlexibleRightMargin]
self.addSubview(assetsView)
self.addSubview(positionView)
self.addSubview(collaboratorView)
}
Upvotes: 0
Views: 79
Reputation: 4209
Try adding .CenterX
& .CenterY
contraints to center each of the subviews:
NSLayoutConstraint(item: view1, attribute: .CenterX, relatedBy: .Equal, toItem: view2, attribute: .CenterX, multiplier: 1, constant: 0).active = true
NSLayoutConstraint(item: view1, attribute: .CenterY, relatedBy: .Equal, toItem: view2, attribute: .CenterY, multiplier: 1, constant: 0).active = true
Upvotes: 1
Reputation: 103
Looks like you only set the relative position with the self.view. If you want three circles have some remain same relative position with each other, you should also set the constraint between them.
Upvotes: 0