- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的问题类似于以下问题:
Negative coordinates in UIView.frame
iOS使用UIKit绘图时,默认原点位于左上角;为什么?
我需要原点位于框架的中心;我想要绘制的坐标包含负数
我一直在搜索,但找不到如何使用 UIKit 在 Swift 3 中绘制数据点
这是我目前拥有的:
import Foundation
import UIKit
@IBDesignable
public class Contours: UIView {
public var gridColor: UIColor = UIColor.clear
public var gridSize: CGSize = CGSize(width: 100, height: 100)
public var gridView = UIView(frame: CGRect(origin: .zero, size: .zero))
public var dataSize: CGSize = CGSize(width: 5, height: 5)
public var dataColor: UIColor = UIColor.blue
public var dataLineColor: UIColor = UIColor.red
public var dataBorderWidth: CGFloat = 1.0
public var dataView = UIView(frame: CGRect(origin: .zero, size: .zero))
public var fade: CGFloat = 0.5
public var distances: [Int] = [2601, 2600, 33, 2608, 2601, 2594, 2625, 2633, 2637, 2651, 2656, 2666, 2683, 2690, 2705, 2712, 2712, 2739, 2752, 53, 1103, 1060, 1019, 980, 944, 911, 33, 851, 826, 801, 777, 757, 737, 718, 701, 683, 667, 654, 53, 486, 470, 457, 448, 440, 432, 424, 416, 409, 403, 396, 389, 383, 378, 372, 367, 362, 357, 353, 348, 344, 340, 336, 333, 329, 326, 323, 319, 317, 314, 311, 309, 307, 305, 303, 301, 299, 298, 297, 295, 294, 293, 292, 291, 290, 290, 290, 290, 291, 293, 295, 303, 386, 383, 53, 350, 53, 53, 53, 53, 53, 3, 364, 362, 360, 356, 358, 355, 353, 351, 350, 349, 347, 345, 53, 53, 53, 308, 3, 309, 309, 312, 313, 315, 316, 319, 321, 53, 329, 332, 335, 332, 53, 53, 53, 53, 53, 53, 53, 3, 53, 53, 53, 53, 53, 53, 670, 33, 706, 728, 750, 772, 799, 825, 856, 887, 925, 755, 749, 744, 739, 734, 730, 727, 722, 719, 716, 714, 634, 709, 706, 704, 703, 701, 699, 700, 695, 697, 697, 338, 696, 697, 696, 698, 698, 700, 702, 703, 705, 707, 710, 712, 714, 718, 53, 53, 53, 53, 53, 53, 53, 53, 3, 53, 53, 53, 53, 53, 53, 53, 53, 3, 53, 53, 53, 53, 53, 53, 53, 3412, 3397, 3384, 53, 3538, 3603, 53, 2426, 2412, 2363, 2330, 2288, 2262, 2214, 2190, 2162, 2130, 53, 53, 53, 2807, 2631, 2408, 2638, 2607, 2601, 2562, 2534, 2515, 2496, 2478, 2462, 2445, 53, 53, 53, 1751, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53, 3, 53, 53, 53, 53, 53, 2643, 2643, 53, 2660, 53, 2528, 2523, 2221, 1955, 1684, 1677, 1684, 1694, 1705, 1202, 1204, 1211, 1217, 1225, 1233, 1239, 1249, 1259, 1270, 1280, 1289, 1280, 1011, 991, 977, 968, 966, 964, 968, 975, 984, 1003, 2, 53, 1297, 53, 53, 33, 1321, 1299, 1274, 1254, 1233, 1232, 1264, 1293, 3802, 53, 53, 53, 53, 53, 53, 53, 3, 53, 2878, 2870, 2848, 2821, 2803, 2788, 2769, 2753, 2740, 2708, 2711, 2701, 2682, 2656, 2664, 2644, 2644, 2631, 2626, 2616, 2610, 2604, 2605, 2605, 2600, 2598, 2603]
public var distx: [Double] = []
public var disty: [Double] = []
public var scalex: [Double] = []
public var scaley: [Double] = []
override public init(frame: CGRect) {
super.init(frame: frame)
}
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
public override func draw(_ rect: CGRect) {
alpha = 1
layer.backgroundColor = gridColor.cgColor
clipsToBounds = false
for index in 0...356 {
let radians = Double(index) * M_PI / 180.0
let x = Double(distances[index]) * cos(Double(radians))
let y = Double(distances[index]) * sin(Double(radians))
distx.append(x)
disty.append(y)
}
let xmin: Double = Double(distx.min()!)
let xmax: Double = Double(distx.max()!)
let ymin: Double = Double(disty.min()!)
let ymax: Double = Double(disty.max()!)
let scale = max(xmax - xmin, ymax - ymin)
var circles = [UIView]()
circles.reserveCapacity(360)
for _ in 0...356 {
circles.append(UIView(frame: CGRect(origin: .zero, size: .zero)))
}
print("width: \(bounds.width), height: \(bounds.height)")
for index in 0...356 {
let radians = Double(index) * M_PI / 180.0
let x = (Double(distances[index]) * cos(Double(radians)) / scale) * Double(325)
let y = (Double(distances[index]) * sin(Double(radians)) / scale) * Double(325)
var aPath = UIBezierPath()
aPath.move(to: CGPoint(x: 0, y: 0))
aPath.addLine(to: CGPoint(x: x, y: y))
UIColor.cyan.set()
aPath.stroke()
aPath.fill()
aPath.close()
circles[index].alpha = 1
circles[index].frame = CGRect(origin: .zero, size: dataSize)
circles[index].center = CGPoint(x: x, y: -y)
circles[index].layer.backgroundColor = dataColor.cgColor
circles[index].layer.borderColor = dataLineColor.cgColor
circles[index].layer.borderWidth = dataBorderWidth
circles[index].layer.cornerRadius = circles[index].bounds.width / 2
if let superview = circles[index].superview {
superview.bringSubview(toFront: circles[index])
} else {
addSubview(circles[index])
}
scalex.append(x)
scaley.append(y)
}
dataView.frame = CGRect(origin: .zero, size: dataSize)
dataView.center = CGPoint(x: bounds.width / 2, y: bounds.height / 2)
dataView.layer.backgroundColor = UIColor.cyan.cgColor
}
private func reset() {
UIView.animate(withDuration: 0.25) { () -> Void in
self.gridView.center = CGPoint(x: self.bounds.width / 2, y: self.bounds.height / 2)
}
}
}
class ViewController: UIViewController {
@IBOutlet private weak var joystickMove: Joystick!
@IBOutlet private weak var joystickRotate: Joystick!
@IBOutlet private weak var objectView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
createJoystick()
createContours()
// joystickMove.trackingHandler = { (joystickData) -> () in
// //print("joystickMove data: \(joystickData)")
//
// let scale: CGFloat = 5.0
//
// self.objectView.center.x += joystickData.velocity.x * scale
// self.objectView.center.y += joystickData.velocity.y * scale
// }
//
// joystickRotate.trackingHandler = { (joystickData) -> () in
// //print("joystickRotate data: \(joystickData)")
//
// self.objectView.transform = CGAffineTransform(rotationAngle: joystickData.angle)
// }
}
private func createJoystick() {
// 1. Initialize an instance of `Joystick` using the constructor:
let joystick = Joystick()
let width: CGFloat = 100
let hieght: CGFloat = 100
let x_center = CGFloat(UIScreen.main.bounds.width/2) - CGFloat(width/2)
let y_center = UIScreen.main.bounds.height - UIScreen.main.bounds.height/4
joystick.frame = CGRect(x: x_center, y: y_center, width: width, height: hieght)
joystick.backgroundColor = UIColor.clear
// 2. Customize the joystick.
joystick.substrateColor = UIColor.lightGray
joystick.substrateBorderColor = UIColor.gray
joystick.substrateBorderWidth = 1.0
joystick.stickSize = CGSize(width: 50, height: 50)
joystick.stickColor = UIColor.darkGray
joystick.stickBorderColor = UIColor.black
joystick.stickBorderWidth = 2.0
joystick.fade = 0.5
// 3. Setup the tracking handler to get velocity and angle data:
// joystick.trackingHandler = { (joystickData) -> () in
// self.objectView.center.x += joystickData.velocity.x
// self.objectView.center.y += joystickData.velocity.y
// }
// 4. Add the joystick to your view:
view.addSubview(joystick)
}
private func createContours() {
let contour = Contours(frame: CGRect(x: 90.0, y: 175.0, width: 250.0, height: 250.0))
view.addSubview(contour)
}
@IBAction func resetButtonTapped(sender: AnyObject) {
UIView.animate(withDuration: 0.5) { () -> Void in
self.objectView.center = self.view.center
// self.objectView.transform = CGAffineTransformIdentity
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
注意我的圆和线的位移:
以前是这样的:
最佳答案
最简单的方法是使用 CGAffineTransform。
这是一个很好的博客,解释了它们:http://iphonedevelopment.blogspot.ca/2008/10/demystifying-cgaffinetransform.html
但是,看起来您所需要的只是翻译。
因此创建您的转换:
let t = CGAffineTransform(translationX: bounds.width/2, y: bounds.height/2)
然后你想要的新坐标集上的每个点
let newPoint = oldPoint.applying(t)
您还可以使用它们来缩放值以适合您的屏幕。这是我用来绘制一些图表的仿射变换作为示例:
let chartTransform = CGAffineTransform(a: innerWidth/xMax, b: 0, c: 0, d: -innerHeight/yMax, tx: origin.x, ty: origin.y + innerHeight)
A 和 D 分别缩放 X 和 Y。因此,我按 View 宽度/最大 X 值的比率缩放 x 值,并按相同比例缩放 y 值。但因为 Y 随着你的下降而增加,所以我用负数翻转了比例。这会将正 y 轴置于垂直方向。为了对此进行调整,我必须将每个值向下平移图表的长度。 origin.x 和 origin.y 只是我开始绘制轴的小缩进。
关于swift - 如何在 UIView Swift 3 中包含负坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40596325/
我有一个非常基本的 MySQL 查询,它从数据库表中读取行并将行值添加或减去定义为 $total_balance 的 PHP 字符串。 例如; $statement_details_query = m
我有 following fiddle ,请注意,如果您使输出的宽度变小,图像将被覆盖并且不会出现滚动条 - 完美。 如果我attempt the same effect on the right ,
这个正则表达式将得到 456。我的问题是为什么它不能是 1-234-56 中的 234 ? 56 是否限定 (?!\d)) 模式,因为它不是单个数字。 (?!\d)) 寻找的起始点在哪里? impor
我需要知道两个子结构之间的内存距离 (&my_type.a - &my_tape.b.c) 结果的类型是什么?我需要将它转换为 (signed int),所以显然它是别的东西。 最佳答案 根据 C11
我遇到了一个扩展异常的异常处理程序类,如下所示: public class AppFileReaderException extends Exception { //Explicit seri
如何可视化负 RGB 值? 根据 OpenCV 文档: CV_8S - 8 位有符号整数 (-128..127) 这是否意味着 -128 表示 0 而 127 表示 255? 如果是,那我们为什么需要
我这里有一段代码给我带来了麻烦: idIndex = panoBuffer.indexOf("\"photo_id\":"); System.out.println(idIndex);
我刚刚练习 Java,对此还很陌生。我只是想创建一个随机数生成器程序来跟踪玩家的获胜、失败、获胜百分比和总获胜金额。该程序的逻辑是,玩家每次 session 有 3 次机会,计算机会生成一个随机数,玩
因此,我们被要求创建一个程序,使用户能够从 1-6 个有关矩阵运算的选项中进行选择。在每个用户的输入中,我们需要检查该输入是否适合要完成的操作(程序应该接受整数或 float ,正数或负数)。如果不满
这是我期望的输出 x |x| 1.2 1.2 -2.3 2.3 3.4 3.4 但我一直收到这个: x |x| 1
假设我有这个: $date1=date_create(date('H:I', strtotime('8:00'))); $date2=date_create(date('H:I', strtotime
如何确定负 FixNum 的无符号解释? # unexpected, true (~0b01111011).to_s(2) == ("-" + (~0b01111011).abs.to_s(2)) #
这是一个用于“邀请您的 friend 加入此群组”脚本的快速 SQL 查询。 我有 2 个表:users 和 group_members。我正在尝试执行一个查询,选择我所有的 friend ——由第一
负 ASCII 值有什么意义? int a = '«'; //a = -85 but as in ASCII table '<<' should be 174 最佳答案 没有负数ASCII值。 ASC
我知道用 PHP 可以做到这一点,但是有没有办法只用 MySQL 来做到这一点? 我有这个数据库: --------------------------------------------------
我在变量中有一个时间戳 $data = (float) -2208988800; 是否可以根据这些数据创建正确的日期?date("d.M.Y", $data) 返回“07.02.2036” 最佳答案
你好我如何将括号格式的负值转换为 double 值。目前我有这个。 Payment.Text = Calc_Payment().ToString("#,##0.00;(#,##0.00)"); 将支付
这是一个小程序。这应该打印 0 或 1,还是它有未定义的行为? #include struct S0 { unsigned f1 : 1; }; struct S0 s; int main (v
运行 lgb.cv 时,我有时会从日志中看到“从分数开始训练”后的负数。想知道这个数字到底是什么意思,单位是什么?是根据参数中指定的指标吗?以下是摘录: [LightGBM] [Info] Total
我正在使用变分自动编码器类型模型,我的损失函数的一部分是均值为 0 和方差为 1 的正态分布与另一个均值和方差由我的模型预测的正态分布之间的 KL 散度。 我用以下方式定义了损失: def kl_lo
我是一名优秀的程序员,十分优秀!