我正在尝试使用UIBezierPath绘制一个指南针并在该线上添加破折号以标记其中的北,南,东,西方向和点.破折号似乎是偏移的(它们没有对齐),特别是在北方和南方方向,而我正在做的方式似乎在路径关闭时添加了额外的破折号.
let windCircleOrigin = CGPoint(x: self.center.x * 1.3, y: self.bounds.height / 2.0 - 10)
let windCircleRadius = CGFloat(self.bounds.height * 0.3)
let windCirclePath: UIBezierPath = UIBezierPath(arcCenter: windCircleOrigin, radius: windCircleRadius,startAngle: 0, endAngle: CGFloat(M_PI) * 2.0, clockwise: true)
windCirclePath.lineWidth = 6
let dashes: [CGFloat] = [windCirclePath.lineWidth * 0, windCirclePath.lineWidth * 3 ]
windCirclePath.setLineDash(dashes, count: dashes.count
, phase: 0.0)
UIColor.whiteColor().setFill()
UIColor.whiteColor().setStroke()
windCirclePath.stroke()
textView(self.windSpeedLabel! + " mph", x: windCircleOrigin.x - 20.0, y: windCircleOrigin.y - 8.0, color: UIColor.whiteColor(), width: 50.0, height: 20.0)
textView("N", x: windCircleOrigin.x - …Run Code Online (Sandbox Code Playgroud) 我刚升级到Xcode 7.1.当我尝试设置GMSMapView的mapType时,我得到错误模糊地使用'kGMSTypeNormal',模糊地使用'kGMSTypeTerrain',以及模糊地使用'kGMSTypeHybrid'.
@IBOutlet weak var mapView: GMSMapView!
func myfunc() {
if let myMapType = NSUserDefaults.standardUserDefaults().stringForKey(SettingsTableViewController.History.MapType) {
switch myMapType {
case "kGMSTypeNormal":
mapView.mapType = kGMSTypeNormal
case "kGMSTypeTerrain":
mapView.mapType = kGMSTypeTerrain
case "kGMSTypeHybrid":
mapView.mapType = kGMSTypeHybrid
default: break
mapView.mapType = kGMSTypeNormal
}
} else {
mapView.mapType = kGMSTypeNormal
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试读取一个 fortran 文件,其标题为整数,然后实际数据为 32 位浮点数。使用 numpyfromfile('mydatafile', dtype=np.float32)它将整个文件读取为 float32,但我需要输出文件的标头位于 int32 中。使用 scipy 的 FortranFile 它读取标题:
f = FortranFile('mydatafile', 'r')
headers = f.read_ints(dtype=np.int32)
Run Code Online (Sandbox Code Playgroud)
但当我这样做时:
data = f.read_reals(dtype=np.float32)
Run Code Online (Sandbox Code Playgroud)
它返回一个空数组。我知道它不应该为空,因为使用 numpy 的 fromfile 它会读取所有数据。奇怪的是,scipy 方法适用于我的数据集中的其他文件,但不适用于这个。也许我不理解 numpy 和 scipy 的两种读取方法之间的区别。使用任一方法读取文件时,是否有办法隔离标头 ( dtype=np.int32) 和数据 ( )?dtype=np.float32
我很确定这是在我的代码部分中发生的情节:
xlows = x[local_min]; xhighs = x[local_max]
ylows = y[local_min]; yhighs = y[local_max]
lowvals = prmsl[local_min]; highvals = prmsl[local_max]
# plot lows as blue L's, with min pressure value underneath.
xyplotted = []
# don't plot if there is already a L or H within dmin meters.
yoffset = 0.022*(m.ymax-m.ymin)
dmin = yoffset
for x,y,p in zip(xlows, ylows, lowvals):
if x < m.xmax and x > m.xmin and y < m.ymax and y > m.ymin:
dist = [np.sqrt((x-x0)**2+(y-y0)**2) for x0,y0 …Run Code Online (Sandbox Code Playgroud) 我正在尝试将CAGradientLayer添加到CAShapeLayer,但渐变不符合图层的形状.相反,渐变呈现出UIView本身的形状.我最初尝试使用UIBezierPath,但它也没有用.我试图在我的形状中加入渐变.
override func drawRect(rect: CGRect) {
let bounds = CGRect(x: 0, y: 0, width: self.bounds.width, height: self.bounds.height)
let center = self.center
let path = CAShapeLayer()
path.bounds = bounds
path.position = CGPoint(x: center.x, y: center.y)
//path.backgroundColor = UIColor.redColor().CGColor
path.cornerRadius = 20
//self.layer.addSublayer(path)
let gradientLayer = CAGradientLayer()
gradientLayer.frame = path.bounds
gradientLayer.colors = [cgColorForRed(209.0, green: 0.0, blue: 0.0),
cgColorForRed(255.0, green: 102.0, blue: 34.0),
cgColorForRed(255.0, green: 218.0, blue: 33.0),
cgColorForRed(51.0, green: 221.0, blue: 0.0),
cgColorForRed(17.0, green: 51.0, blue: 204.0),
cgColorForRed(34.0, green: 0.0, blue: 102.0), …Run Code Online (Sandbox Code Playgroud) 我试图弄清楚如何获得包含uitextview的tableview单元格的正确高度,以便显示uitextview中的所有内容.textview不可编辑且不可滚动,这意味着uitextview的字符串是已知的.我尝试简单地返回故事板中的tableview单元格的高度,heightForRowAtIndexPath但是如果内容太大则会切断内容.我也尝试计算textView的高度,heightForRowAtIndexPath但它在运行时抛出一个错误:
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
let cellInfo = UserCellsArray[indexPath.section]
switch cellInfo {
case .userInfo: return 104
case .ubio:
let cell = tableView.dequeueReusableCellWithIdentifier(cellInfo.description, forIndexPath: indexPath) as! UserProfileTableViewCell //error
let oldHeight = cell.userBio.frame.size.height
cell.userBio.text = self.bio
var bodyframe = cell.userBio.frame
bodyframe.size = cell.userBio.contentSize
let newHeight = cell.userBio.contentSize.height
return tableView.rowHeight - oldHeight + newHeight
}
}
Run Code Online (Sandbox Code Playgroud) ios ×4
swift ×4
python ×2
swift2 ×2
gmsmapview ×1
matplotlib ×1
numpy ×1
scipy ×1
uibezierpath ×1
uitableview ×1
unicode ×1