以及什麼我想要實現這個庫https://github.com/Vinodh-G/ParallaxTableViewHeader但在實現這個庫時遇到的問題:添加模糊效果,而對視差頭(SWIFT)滾動
問題:
其對
ObjC
和我的母語是Swift
,所以它很難理解發生了什麼事情不知何故我實現了這個庫,但headerView的圖像不在中心,我試圖設置ContentMode到scaletofill,中心但它並沒有爲我工作
其出現這樣的(不是中心,直到我有一次滾動)
滾動後:
所以我創造了我自己和它的工作的罰款只有一個PROBL EM是,我沒有任何模糊的效果還,所以如果有人知道它是如何工作或我如何才能增加我的HeaderView這個模糊的效果,那麼請讓我知道
我(SWIFT)HeaderView:
class HeaderView: UIView {
var heightLayoutConstraint = NSLayoutConstraint()
var bottomLayoutConstraint = NSLayoutConstraint()
var containerView = UIView()
var containerLayoutConstraint = NSLayoutConstraint()
override init(frame: CGRect) {
super.init(frame: frame)
self.backgroundColor = UIColor.whiteColor()
// The container view is needed to extend the visible area for the image view
// to include that below the navigation bar. If this container view isn't present
// the image view would be clipped at the navigation bar's bottom and the parallax
// effect would not work correctly
containerView.translatesAutoresizingMaskIntoConstraints = false
containerView.backgroundColor = UIColor.redColor()
self.addSubview(containerView)
self.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[containerView]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["containerView" : containerView]))
self.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:[containerView]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["containerView" : containerView]))
containerLayoutConstraint = NSLayoutConstraint(item: containerView, attribute: .Height, relatedBy: .Equal, toItem: self, attribute: .Height, multiplier: 1.0, constant: 0.0)
self.addConstraint(containerLayoutConstraint)
let imageView: UIImageView = UIImageView.init()
imageView.translatesAutoresizingMaskIntoConstraints = false
imageView.backgroundColor = UIColor.whiteColor()
imageView.clipsToBounds = true
imageView.contentMode = .ScaleAspectFill
imageView.image = UIImage(named: "cover")
containerView.addSubview(imageView)
containerView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[imageView]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: ["imageView" : imageView]))
bottomLayoutConstraint = NSLayoutConstraint(item: imageView, attribute: .Bottom, relatedBy: .Equal, toItem: containerView, attribute: .Bottom, multiplier: 1.0, constant: 0.0)
containerView.addConstraint(bottomLayoutConstraint)
heightLayoutConstraint = NSLayoutConstraint(item: imageView, attribute: .Height, relatedBy: .Equal, toItem: containerView, attribute: .Height, multiplier: 1.0, constant: 0.0)
containerView.addConstraint(heightLayoutConstraint)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
func scrollViewDidScroll(scrollView: UIScrollView) {
containerLayoutConstraint.constant = scrollView.contentInset.top;
let offsetY = -(scrollView.contentOffset.y + scrollView.contentInset.top);
containerView.clipsToBounds = offsetY <= 0
bottomLayoutConstraint.constant = offsetY >= 0 ? 0 : -offsetY/2
heightLayoutConstraint.constant = max(offsetY + scrollView.contentInset.top, scrollView.contentInset.top)
}
}
嗨@Sushree我剛剛試過你的答案,是的它的工作正常,但我仍然希望模糊讓我嘗試,如果我得到一個選項 –