Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Showing page number using custom overlay on initial launch? #26

Open
seenoevo opened this issue Jul 9, 2017 · 1 comment
Open

Showing page number using custom overlay on initial launch? #26

seenoevo opened this issue Jul 9, 2017 · 1 comment

Comments

@seenoevo
Copy link

seenoevo commented Jul 9, 2017

I'm having issues trying to show the X of Y paging in the navigation bar title when the gallery initially launches.

I'm using my own custom overlay using the following code:

class CustomGalleryOverlay: INSNibLoadedView, INSPhotosOverlayViewable
{
    @IBOutlet var navigationBar: UINavigationBar!
    @IBOutlet var toolBar: UIToolbar!
    
    var photosViewController: INSPhotosViewController?
    
    override init(frame: CGRect)
    {
        super.init(frame: frame)
        navigationBar.isTranslucent = true
    }
    
    required public init?(coder aDecoder: NSCoder)
    {
        fatalError("init(coder:) has not been implemented")
    }
    
    // Pass the touches down to other views
    override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView?
    {
        if let hitView = super.hitTest(point, with: event) , hitView != self
        {
            return hitView
        }
        return nil
    }
    
    func populateWithPhoto(_ photo: INSPhotoViewable)
    {
        if let photosViewController = photosViewController
        {
            if let index = photosViewController.dataSource.indexOfPhoto(photo)
            {
                navigationBar.topItem?.title = String(format:NSLocalizedString("%d of %d",comment:"dasdas"), index + 1, photosViewController.dataSource.numberOfPhotos)
            }
        }
    }
    
    func setHidden(_ hidden: Bool, animated: Bool)
    {
        if self.isHidden == hidden
        {
            return
        }
        
        if animated
        {
            self.isHidden = false
            self.alpha = hidden ? 1.0 : 0.0
            
            UIView.animate(withDuration: 0.2, delay: 0.0, options: [.allowAnimatedContent, .allowUserInteraction], animations: { () -> Void in
                self.alpha = hidden ? 0.0 : 1.0
            }, completion: { result in
                self.alpha = 1.0
                self.isHidden = hidden
            })
        }
        else
        {
            self.isHidden = hidden
        }
    }

    @IBAction func closeGallery(_ sender: UIBarButtonItem)
    {
        photosViewController?.dismiss(animated: true, completion: nil)
    }

However, when I launch the gallery, the X of Y paging telling you what image you're on does not appear initially until I scroll to the second image.

And if I have only one image, the paging doesn't show at all.

Can someone assist?

Thanks!

@seenoevo
Copy link
Author

seenoevo commented Jul 9, 2017

@m1entus

Not sure if this is the "correct" way to do it but I resolved it by invoking populateWithPhtoto in the following didSelectItemAt:

 func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
 {
        ...
        galleryPreview.overlayView = CustomGalleryOverlay(frame: CGRect.zero)
        
        galleryPreview.overlayView.populateWithPhoto(images[(indexPath as NSIndexPath).row])
        ....
 }

Can you confirm if this is correct? Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant