试图保持“圆度”'用户旋转设备时的UIButton:
func resizeButtons() {
startButton.layer.masksToBounds = true
startButton.layer.cornerRadius = self.startButton.frame.size.width / 2
startButton.layer.borderColor = UIColor.blackColor().CGColor
startButton.layer.borderWidth = 1.0
}
override func didRotateFromInterfaceOrientation(fromInterfaceOrientation: UIInterfaceOrientation) {
switch UIDevice.currentDevice().orientation{
case .Portrait:
self.resizeButtons()
case .PortraitUpsideDown:
self.resizeButtons()
case .LandscapeLeft:
self.resizeButtons()
case .LandscapeRight:
self.resizeButtons()
default:
print("default")
}
}
我正在使用自动布局和StoryBoards(按钮宽高比1:1,纵横比按钮到容器视图1:3,按钮中心水平和垂直于容器)。
结果有点麻烦和丑陋'当设备旋转时,UIButton变成圆角矩形,然后是整圆。