斯威夫特,我如何创建一个图像映射作为html映射



我想创建图像映射作为HTML图像映射。例如:

<map name="car-damage-map">
    <area alt="side1" coords="31,274,197,207,304,186,417,176,460,182,652,65,736,32,869,6,1020,2,1118,8,1229,15,1274,21,1292,18,1308,4,1309,13,1304,27,1361,46,1457,81,1573,131,1592,138,1682,160,1722,161,1719,181,1728,209,1725,215,1708,249,1718,286,1753,324,1751,374,1757,399,1717,466,1659,469,1533,476,1506,479,1476,524,1437,555,1366,567,1307,539,1261,479,461,483,398,554,322,563,287,555,224,484,56,482,5,468,11,465,11,456,1,447,8,433,8,400,0,394,3,348,16,341,8,331,22,295,21,297,36,295" onclick="CarDetails.pointIsClicked(event)" shape="poly"></area>
    <area alt="side2" coords="40,870,159,849,184,841,394,758,458,739,452,712,483,729,729,711,862,715,1017,737,1112,778,1204,833,1279,877,1304,891,1336,884,1513,909,1639,937,1701,968,1730,986,1726,999,1739,1005,1754,1038,1744,1045,1756,1054,1756,1107,1753,1145,1757,1157,1751,1168,1754,1174,1698,1193,1534,1195,1502,1243,1446,1268,1389,1271,1324,1235,1292,1193,499,1186,468,1237,393,1272,341,1270,296,1248,253,1183,180,1178,134,1170,100,1167,97,1175,40,1174,2,1110,11,1092,5,1032,33,1011,54,958,40,927,30,922,42,898" onclick="CarDetails.pointIsClicked(event)" shape="poly"></area>
    <area alt="top" coords="2,1770,11,1636,38,1523,86,1478,151,1451,206,1434,266,1423,478,1423,519,1431,819,1430,846,1425,897,1424,905,1433,1091,1431,1078,1386,1086,1382,1118,1391,1137,1423,1141,1429,1232,1434,1335,1425,1539,1428,1605,1450,1686,1514,1727,1580,1741,1621,1758,1774,1743,1926,1708,2006,1653,2063,1544,2116,1383,2122,1289,2119,1252,2114,1140,2116,1123,2148,1084,2160,1090,2117,906,2113,880,2124,830,2120,821,2111,522,2113,484,2121,370,2124,265,2118,203,2114,140,2090,77,2062,42,2024,11,1916" onclick="CarDetails.pointIsClicked(event)" shape="poly"></area>
    <area alt="front" coords="2085,430,2288,415,2294,399,2297,415,2520,430,2596,584,2609,590,2626,553,2658,557,2687,569,2688,598,2642,607,2635,631,2641,684,2647,707,2642,815,2643,975,2553,981,2551,920,2037,920,2037,976,1944,982,1943,821,1940,694,1954,639,1947,605,1906,599,1893,581,1912,563,1959,553,1975,593,1991,584,2060,433" onclick="CarDetails.pointIsClicked(event)" shape="poly"></area>
    <area alt="front" coords="2090,1207,2293,1195,2502,1209,2534,1224,2594,1357,2606,1361,2613,1366,2621,1331,2649,1330,2680,1348,2683,1370,2636,1384,2630,1398,2646,1468,2644,1584,2639,1615,2636,1751,2546,1751,2542,1672,2450,1668,2151,1670,2118,1673,2045,1670,2041,1745,2035,1754,1954,1752,1947,1607,1939,1465,1954,1397,1953,1385,1916,1375,1906,1369,1903,1349,1964,1329,1976,1364,1995,1357,2056,1221" onclick="CarDetails.pointIsClicked(event)" shape="poly"></area>
  </map>

我知道每个图像的边界。此边界是 HTML 中的区域。我想知道每个区域的点是否

此功能可以通过将 UITapGestureRecognizer 添加到所需组件并检查点击原点 (x, y( 来实现,在此基础上,您可以确定已点击的区域。

例如:

class ViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        let tapGesture = UITapGestureRecognizer(target: self, action: #selector(tapGestureAction(_:)))
        view.addGestureRecognizer(tapGesture)
    }
    func tapGestureAction(_ tapGesture: UITapGestureRecognizer) {
        let tappedLocationPoint = tapGesture.location(in: view)
        print(tappedLocationPoint.x)
        print(tappedLocationPoint.y)
        // determining which area has been tapped based on what's the value of x and y
        // you logic goes here...
        // ...
    }
}

相关内容

  • 没有找到相关文章

最新更新