2016-06-10 18 views
0

gut, was in dieser Bibliothek zu erreichen versuchen, ist https://github.com/Vinodh-G/ParallaxTableViewHeader aber Problem habe, während diese Bibliothek Umsetzung:Unschärfe-Effekt hinzufügen, während auf Parallax-Header (Swift) Scrollen

Problem:

  1. seine auf ObjC und meine Muttersprache ist Swift so ist es schwer zu verstehen, was unter der Haube ist

  2. irgendwie habe ich diese Bibliothek implementiert, aber das Bild von headerView ist nicht auf der Mitte, ich versucht, die ContentMode zu setzen Center scaletofill, aber es hat für mich

    nicht arbeitete

seine wie diese erscheinen (nicht in der Mitte, bis ich einmal scrollen)

enter image description here so

nach dem Scrollen :

enter image description here

also habe ich meine eigene und seine adaequat nur eine probl em ist, dass ich nicht haben noch keine Unschärfe-Effekt, so dass, wenn jemand weiß, wie das funktioniert, oder wie kann ich diese Unschärfe-Effekt auf meine HeaderView hinzufügen dann lass es mich wissen

meine (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) 
} 

}

Antwort

1

Nun, anstatt zu versuchen, um das Bild zu verwischen können Sie einen Overlay über Ihr Bild hinzufügen, was natürlich zu Clear gesetzt ist() und dann, während Sie die Hintergrundfarbe Ihres Overlay Blicks auf diesen Satz nach oben: -

UIColor(white: 1.0, alpha: scrollView.contentOffset.y/180) 

Hinweis, ich hatte eine Tabelle verwendet, die zwei verschiedene Arten von Zellen (eine parallaxHeaderViewCell mit imageView und die overlayView darüber und eine andere eine normale Zelle für tableView) festgelegt. Die Scroll ich geschrieben habe, ist von: -

func scrollViewDidScroll(scrollView: UIScrollView!) 

Ich habe meinen eigenen Code zu verwendet Parallaxe zu implementieren, anstatt von Drittanbietern zu implementieren. Es ist einfach zu implementieren und keine große Sache !!

+0

hey @Sushree Ich habe gerade versucht Ihre Antwort und ja es funktioniert gut, aber ich will immer noch die Unschärfe lassen Sie mich versuchen, wenn ich eine Option bekomme –