BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / mobile-terminal-at / #23522同步于 2015/7/13
该镜像源已超过 30 天没有更新,可能在源站已被删除。
MobileTerminalAT机器人发帖

[问题]Swift莫名其妙的的问题,求解惑!

wz61
2015/7/13镜像同步6 回复
划线的部分给我报错说FaceUIView.Type does not have a member named 'dataSource' import UIKit protocol FaceViewDataSource : class { func smilinessForFaceView(sender : FaceUIView) ->Double? } @IBDesignable class FaceUIView: UIView { @IBInspectable var scale :CGFloat = 0.5 { didSet { setNeedsDisplay()}} @IBInspectable var faceCenter : CGPoint { let newCenter = convertPoint(center, fromView: superview) println(newCenter.x) return newCenter } var faceRadius : CGFloat { return min(bounds.size.width, bounds.size.height) / 2 * scale } var lineWidth : CGFloat = 3 { didSet {setNeedsDisplay()}} var color : UIColor = UIColor.blueColor() {didSet {setNeedsDisplay()}} weak var dataSource : FaceViewDataSource? let smiliness = dataSource?.smilinessForFaceView(self) ?? 0.0 private struct Scaling{ static let FaceRadiusToEyeRadiusRatio : CGFloat = 10 static let FaceRadiusToEyeOffsetRatio : CGFloat = 3 static let FaceRadiusToEyeSeparationRatio : CGFloat = 1.5 static let FaceRadiusToMouthWidthRatio : CGFloat = 1 static let FaceRadiusToMouthHeightRatio : CGFloat = 3 static let FaceRadiusToMouthOffsetRatio : CGFloat = 3 } private func bezierPathForSmile(fractionOfMaxSmile: Double)->UIBezierPath { let mouthWidth = faceRadius / Scaling.FaceRadiusToMouthWidthRatio let mouthHeight = faceRadius / Scaling.FaceRadiusToMouthHeightRatio let mouthVerticalOffset = faceRadius / Scaling.FaceRadiusToMouthOffsetRatio let smileHeight = CGFloat(max(min(fractionOfMaxSmile, 1), -1)) * mouthHeight let start = CGPoint(x: faceCenter.x - mouthWidth / 2, y: faceCenter.y + mouthVerticalOffset) let end = CGPoint(x: start.x + mouthWidth, y: start.y) let cp1 = CGPoint(x: start.x + mouthWidth, y: start.y + smileHeight) let cp2 = CGPoint(x: end.x - mouthWidth, y: cp1.y ) let path = UIBezierPath() path.moveToPoint(start) path.addCurveToPoint(end, controlPoint1: cp1, controlPoint2: cp2) path.lineWidth = lineWidth return path } func scale(gesture : UIPinchGestureRecognizer){ if gesture.state == .Changed { scale *= gesture.scale gesture.scale = 1 } } override func drawRect(rect: CGRect) { let facePath = UIBezierPath(arcCenter: faceCenter, radius: faceRadius, startAngle: 0, endAngle: CGFloat(2*M_PI), clockwise: true) facePath.lineWidth = lineWidth color.set() facePath.stroke() let smiliness = 0.75 let smilePath = bezierPathForSmile(smiliness) smilePath.stroke() } }
订阅后,新回复会通过你的通知中心匿名送达。
6 条回复
wangxiaobupt机器人#1 · 2015/7/13
看了一下 没觉得有什么问题
Aprilcxn机器人#2 · 2015/7/14
把两句话删了重新一步一步写一下试试? 先看看是不是有了datasource变量 再看看能不能用? 有时候是有些很奇怪的地方 比如很多符号左右要加空格之类的。。
wz61机器人#3 · 2015/7/14
已经弄明白了,就是编辑器有bug,把代码用文本洗一下就好了 【 在 Aprilcxn 的大作中提到: 】 : 把两句话删了重新一步一步写一下试试? 先看看是不是有了datasource变量 再看看能不能用? : 有时候是有些很奇怪的地方 比如很多符号左右要加空格之类的。。 : 发自「贵邮」
Aprilcxn机器人#4 · 2015/7/14
噢噢 那就好 【 在 wz61 的大作中提到: 】 : 已经弄明白了,就是编辑器有bug,把代码用文本洗一下就好了 : : 发自「贵邮」
zxy机器人#5 · 2015/7/15
过了一年了仍然有BUG么……
wz61机器人#6 · 2015/7/17
【 在 zxy 的大作中提到: 】 : 过了一年了仍然有BUG么…… : 嗯,虽然不是beta版了,但是bug还是很多,毕竟太智能了. 发自「贵邮」