我正在努力使用左、右、上、下锚点进行设备旋转。
对于正确的风景,您应该对顶部边缘和状态栏保持安静。
如果您正确理解视图层次结构,则可以使用以下代码示例:
let deleteButtonImage = UIImage(named: "DeleteButton") as UIImage?
let deleteButtonImageSize: CGSize = CGSize(width: 295, height: 45)
let deleteButton = UIButton(type: UIButton.ButtonType.custom)
deleteButton.translatesAutoresizingMaskIntoConstraints = false
deleteButton.tintColor = .white
deleteButton.frame = CGRect(x: 0, y: 0, width: 250, height: 135)
deleteButton.setImage(deleteButtonImage, for: .normal)
deleteButton.imageEdgeInsets = UIEdgeInsets(
top: (deleteButton.frame.size.height - deleteButtonImageSize.height) / 2,
left: (deleteButton.frame.size.width - deleteButtonImageSize.width) / 2.5,
bottom: (deleteButton.frame.size.height - deleteButtonImageSize.height) / 2,
right: (deleteButton.frame.size.width - deleteButtonImageSize.width) / 2.5)
scrollView.addSubview(deleteButton)
deleteButton.rightAnchor.constraint(equalTo: self.view.rightAnchor).isActive = true
deleteButton.leftAnchor.constraint(equalTo: self.view.leftAnchor, constant: -150).isActive = true
deleteButton.topAnchor.constraint(equalTo: scrollView.topAnchor, constant: 370).isActive = true
deleteButton.widthAnchor.constraint(equalTo: self.scrollView.safeAreaLayoutGuide.widthAnchor).isActive = true
deleteButton.heightAnchor.constraint(equalToConstant: 45).isActive = true
}