如何解决旋转按钮导致改变框架
按钮的黄色部分:
内部PanGesture:
case .changed:
tempAngle = atan2(touchPoint.y - nailPoint.y,touchPoint.x - nailPoint.x)
changedAngle = tempAngle
let distance = distanceFromTwoPoints(nailPoint,touchPoint)
drawTempUnitButton(buttonPoint: nailPoint,unitButtonWidth: distance,anchorPoint: currentAnglePoint,angle: tempAngle,button: tempUnitButton,unitValue: distance)
我如何创建按钮,宽度和高度都是固定的
func drawTempUnitButton(buttonPoint:CGPoint,unitButtonWidth:CGFloat,anchorPoint:CGPoint,angle:CGFloat,button:UIButton,unitValue:CGFloat){
self.addSubview(button)
button.frame = CGRect(x: buttonPoint.x,y: buttonPoint.y,width: unitButtonWidth,height: 30)
let floatUnitValue = Float(unitValue)
let buttonTxt = String(floatUnitValue)
button.setTitle(buttonTxt,for: .normal)
button.titleLabel?.textAlignment = .center
button.setTitleColor(.red,for: .normal)
button.titleLabel?.font = .boldSystemFont(ofSize: 16)
button.backgroundColor = UIColor.yellow
button.setAnchorPoint(anchorPoint)
let transform = CGAffineTransform(rotationAngle: angle)
button.transform = transform
}
这是什么问题?
解决方法
根据Leo Dabus的评论,我修复了这些问题
button.frame = CGRect(x: buttonPoint.x,y: buttonPoint.y,width: 0,height: 0)
button.bounds.size.width = unitButtonWidth
button.bounds.size.height = 30
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。