ios - 模拟器与真实手机中的内容变化
问题描述
我有一个高度为 110 的小部件。我正在使用 UIBezierPath 以编程方式制作一个圆圈。我在小部件中有一个名为 ClockView(宽度和高度为 80)的视图,它以 x 轴为中心,它的中心也应该是圆的中心。正如您将在模拟器屏幕截图中看到的那样,我能够实现这一点,但是在实际设备上运行时,它完全关闭。
let centerY = 15 + clockView.frame.size.height/2
let centerX = 15 + clockView.frame.size.width/2
let centerPoint = CGPoint(x: centerX, y: centerY)
let circularPath = UIBezierPath(arcCenter: centerPoint, radius: circleRadius, startAngle: -CGFloat.pi / 2, endAngle: 3 * CGFloat.pi / 2, clockwise: true)
完整的视图设置代码
override func viewDidLoad() {
super.viewDidLoad()
timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector:#selector(self.refresh) , userInfo: nil, repeats: true)
circleRadius = CGFloat(2*(clockView.frame.size.height/2)/2.4)
lineWidth = Double(circleRadius/5)
//view.backgroundColor = UIColor(red:0.95, green:0.97, blue:1.00, alpha:1.0)
let trackLayer = CAShapeLayer()
let guide = view.safeAreaLayoutGuide
let height = guide.layoutFrame.size.height
let padding = (height - clockView.frame.size.width)/2
print("PADDING = \(padding)")
let centerY = 15 + clockView.frame.size.height/2
let centerX = 15 + clockView.frame.size.width/2
let centerPoint = CGPoint(x: centerX, y: centerY)
let circularPath = UIBezierPath(arcCenter: centerPoint, radius: circleRadius, startAngle: -CGFloat.pi / 2, endAngle: 3 * CGFloat.pi / 2, clockwise: true)
trackLayer.path = circularPath.cgPath
trackLayer.strokeColor = UIColor(red:0.92, green:0.96, blue:1.00, alpha:1.0).cgColor
trackLayer.lineWidth = CGFloat(lineWidth)
trackLayer.fillColor = UIColor.clear.cgColor
trackLayer.lineCap = kCALineCapRound
trackLayer.shadowColor = UIColor(red:0.46, green:0.57, blue:0.68, alpha:1.0).cgColor
trackLayer.shadowRadius = 13
trackLayer.shadowOffset = CGSize(width: 0, height: 0)
trackLayer.shadowOpacity = 0.3
view.layer.addSublayer(trackLayer)
completeLayer.path = circularPath.cgPath
completeLayer.strokeColor = UIColor(red:0.50, green:0.73, blue:0.98, alpha:1.0).cgColor
completeLayer.lineWidth = CGFloat(lineWidth)
completeLayer.fillColor = UIColor.clear.cgColor
completeLayer.lineCap = kCALineCapRound
completeLayer.strokeEnd = 0
view.layer.addSublayer(completeLayer)
let topCirclePath = UIBezierPath(arcCenter: centerPoint, radius: CGFloat(Double(circleRadius)-Double(lineWidth)), startAngle: -CGFloat.pi / 2, endAngle: 2 * CGFloat.pi, clockwise: true)
timeLayer.path = topCirclePath.cgPath
timeLayer.strokeColor = UIColor(red:0.92, green:0.96, blue:1.00, alpha:1.0).cgColor
timeLayer.lineWidth = CGFloat(lineWidth)
timeLayer.fillColor = UIColor(red:0.92, green:0.96, blue:1.00, alpha:1.0).cgColor
timeLayer.lineCap = kCALineCapRound
timeLayer.shadowRadius = 10
timeLayer.shadowOffset = CGSize(width: 0, height: 0)
timeLayer.shadowColor = UIColor.black.cgColor
timeLayer.shadowOpacity = 0.2
view.layer.addSublayer(timeLayer)
view.layer.insertSublayer(clockView.layer, above: timeLayer)
refresh()
// Do any additional setup after loading the view from its nib.
}
解决方案
第一步是仔细检查您的手机和模拟器是否是相同的 iOS 和型号。
帖子的第二件事,可能会发布更多代码,显示有问题的确切项目/元素。(即您所拥有的标签/项目,它可能缺少硬件所需的某种项目/标签/值。)
希望有帮助。
推荐阅读
- entity-framework-core - Entity Core 和 SaveChanges 只工作一次
- python-3.x - 如何使用交叉验证和预测标签测试看不见的测试数据?
- android - 如果你想用它来保护整个应用程序(例如银行应用程序),你如何正确配置 local_auth?
- javascript - 检查 HTML 元素是否在视口中
- amp-html - amp-script:innerHTML 按原样呈现与符号转义的序列
- aspnetboilerplate - 获取 ABP .NET 核心框架中的所有父表行和所有子表行
- javascript - Javscript Math.Pow 乘法
- linux - 我们可以在 azure 管道 yaml 文件中编写用户定义函数吗?
- ubuntu - 我无法重新启动 ssh (git bash)
- azure - Azure APIM VNet 卡住