Search code examples
iosmwphotobrowser

Can't scroll between images


For some reason I can't scroll between different photos, can someone spot my mistake? So here's my code:

import UIKit
import MWPhotoBrowser

class TETSViewController: MWPhotoBrowser, MWPhotoBrowserDelegate {

    var photo = [MWPhoto]()

    override func viewDidLoad() {
        super.viewDidLoad()

        displayActionButton = false
        displaySelectionButtons = false
        displayNavArrows = false
        enableGrid = false
        startOnGrid = false
        autoPlayOnAppear = false
        zoomPhotosToFill = true
        enableSwipeToDismiss = false
        setCurrentPhotoIndex(0)
    }

    func numberOfPhotosInPhotoBrowser(photoBrowser: MWPhotoBrowser!) -> UInt {
        return UInt(photo.count)
    }

    override func photoAtIndex(index: UInt) -> MWPhotoProtocol! {
        if index < UInt(photo.count) {
            return photo[Int(index)]
        } else {
            return nil
        }
    }

    func photoBrowser(photoBrowser: MWPhotoBrowser!, photoAtIndex index: UInt) -> MWPhotoProtocol! {
        if index < UInt(photo.count) {
            return photo[Int(index)]
        } else {
            return nil
        }
    }
}

I think I did everything line in official MWPhotoBrowser example, but at only one photo is being shown. By the way, this view is being loaded when I selected cell from table view, then using prepareForSegue I assign 5 images to photo and print(photo.count) does print 5.


Solution

  • Add the following code to the function layoutSubviews in MWZoomingScrollView.m. it works for me.

    self.contentSize = CGSizeMake(floorf(self.contentSize.width), floorf(self.contentSize.height));
    

    See https://github.com/mwaterfall/MWPhotoBrowser/issues/389.