Amnell/APParallaxHeader

On first load the image appears halfway down until you first scroll (either up or down) from a callback.

gotnull opened this issue · 4 comments

Example code:

func getPhoto(callback: (Array<AnyObject>) -> ()) {
    let urlPath: NSString = "some_rest_url"
    let url = NSURL(string: urlPath)

    let request = NSMutableURLRequest(URL: url)
    request.HTTPMethod = "GET"
    request.addValue("application/json", forHTTPHeaderField: "Accept")

    let session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration(), delegate: self, delegateQueue: NSOperationQueue.mainQueue())

    var dataTask = NSURLSessionDataTask()
    dataTask = session.dataTaskWithRequest(request) { (data, response, error) in
        if (error == nil) {
            callback(array)
        }
    }
    dataTask.resume()
}

override func viewDidLoad() {
    super.viewDidLoad()

    // Works fine here with any image.
    //let venueImage = UIImage(named: "bg")
    //self.tableView.addParallaxWithImage(venueImage, andHeight: 160)

    // Bug occurs here, when coming from callback.
    api.getPhoto() { (photos) in
        let photo = photos[0] as FSPhoto
        let data = NSData(contentsOfURL: NSURL.URLWithString("\(photo.prefix)300x300\(photo.suffix)"))
        let venueImage = UIImage(data: data)
        let venueImage = UIImage(named: venueImage)
        self.tableView.addParallaxWithImage(venueImage, andHeight: 160)
    }
}

First Load (from callback method):

Image of Problem

When scrolling for the first time (either up or down), the image appears where it should be.

The image appears properly otherwise if it's just a simple call within the viewDidLoad.

Image of Fixed

I am having the same issue. Please help.

Same issue. Any updates?

Unfortunately I never received an update on this issue. Never managed to resolve it either.

On 29 Sep 2014, at 9:04 pm, Johan Bååth notifications@github.com wrote:

Same issue. Any updates?


Reply to this email directly or view it on GitHub.

A simple work-around is to move the contentOffset to the top in the viewDidLoad function.

Example:

self.tableView.contentOffset = CGPointMake(0, 0 - self.tableView.contentInset.top);