如何解决缩放后如何使边框的宽度相同?
我为视图设置了“ borderwidth = 3”。我缩放后,边框变得更粗或更细。
缩放之前(左照片上的黄色边框) 缩放后(右侧照片上的黄色边框) enter image description here
缩放边框后如何保持边框的宽度固定?
我在GitHub上使用了此源 https://github.com/yokurin/DragRotateScaleView
然后只需添加v.layer.borderWidth = 5
lazy var rect1: DragRotateScaleView = {
let v = DragRotateScaleView(frame: CGRect(x: 20,y: 100,width: 200,height: 200))
v.delegate = self
v.backgroundColor = UIColor.cyan
v.layer.borderColor = UIColor(red: 22/255,green: 22/255,blue: 22/255,alpha: 1).cgColor
v.layer.borderWidth = 5
return v
}()
谢谢!
解决方法
只需将边框宽度除以比例,然后再次将该值设置为borderWidth
。
在操场上尝试:
import UIKit
import PlaygroundSupport
// Save this values,you will use them.
let border: CGFloat = 3
let scale: CGFloat = 5
// Example views.
let view = UIView(frame: CGRect(x: 0,y: 0,width: 500,height: 500))
view.backgroundColor = .red
let secondView = UIView(frame: CGRect(x: 0,width: 100,height: 100))
secondView.layer.borderColor = UIColor.yellow.cgColor
secondView.layer.borderWidth = border
view.addSubview(secondView)
// View scale transformation.
secondView.transform = CGAffineTransform(scaleX: scale,y: scale)
// IMPORTANT: Change the width of the border after the transformation.
secondView.layer.borderWidth = border / scale
// This is only for the playground.
PlaygroundPage.current.liveView = view
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。