为什么我的UIView
在不同的iPhone屏幕尺寸上有不同的位置?我想这是因为autoresizingMask
,但我应用autoresizingMask
后如何获得一个视图框架,以创建一些通用逻辑?或什么是处理这个最好的做法?为什么我的UIView在不同的iPhone上有不同的位置?
这里是代码:
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)
}
你为什么编程这样做呢?在Storyboard –
@ matt.writes.code中使用自动布局约束会容易得多。我不能在这里使用storyboard –