我有ViewController
多个自定义视图。CustomView
有一个名为的 xibcustomView.xib
并在CustomView.swift
.
CustomView
具有文本字段,其委托在CustomView.swift
.
CustomView
当点击里面的文本字段时ViewController
,委托方法:
func textFieldDidBeginEditing(textField: UITextField) {
var field = textField as! AddItemTextField
ViewController?.makeViewOffset(self.bounds.origin.y - 20)
}
}
函数 make offset 在以下位置实现ViewController
:
func makeViewOffset(offset: CGFloat) {
UIView.animateWithDuration(0.5, animations: { () -> Void in
self.scrollView.contentOffset.y = offset
})
}
所以,我想要实现的是:当一些customViews被点击时,在我的scrollView中获取它们的位置,并使scrollView偏移到这个值,这样视图就会在滚动的顶部可见。
我目前所在的位置:我的界限为零,我无法将坐标传递给CustomView.swift
有什么建议吗?