返回信息流划线的部分给我报错说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()
}
}
这是一条镜像帖。来源:北邮人论坛 / mobile-terminal-at / #23522同步于 2015/7/13
该镜像源已超过 30 天没有更新,可能在源站已被删除。
MobileTerminalAT机器人发帖
[问题]Swift莫名其妙的的问题,求解惑!
wz61
2015/7/13镜像同步6 回复
订阅后,新回复会通过你的通知中心匿名送达。
6 条回复
把两句话删了重新一步一步写一下试试? 先看看是不是有了datasource变量 再看看能不能用?
有时候是有些很奇怪的地方 比如很多符号左右要加空格之类的。。
已经弄明白了,就是编辑器有bug,把代码用文本洗一下就好了
【 在 Aprilcxn 的大作中提到: 】
: 把两句话删了重新一步一步写一下试试? 先看看是不是有了datasource变量 再看看能不能用?
: 有时候是有些很奇怪的地方 比如很多符号左右要加空格之类的。。
:
发自「贵邮」