 class IGStoryViewController: UIViewController {
 
     public var imagearray:Array! = []
-    
+    var currentindex = 0
+    var timer:Timer? = nil
     @IBOutlet weak var collectionview: UICollectionView! {
         didSet {
         

            collectionview.dataSource = self
            let storyNib = UINib.init(nibName: IGStoryCollectionViewCell.reuseIdentifier(), bundle: nil)
            collectionview.register(storyNib, forCellWithReuseIdentifier: IGStoryCollectionViewCell.reuseIdentifier())
            
            let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
            layout.minimumInteritemSpacing = 0
            layout.minimumLineSpacing = 0
            layout.scrollDirection = .horizontal
            
        }
    }
    

        
        self.title = "Story"
        //self.automaticallyAdjustsScrollViewInsets = false

        timer = Timer.scheduledTimer(timeInterval: 5.0, target: self, selector: #selector(IGStoryViewController.scrolltonextcell), userInfo: nil, repeats: false)
        
    }
    
    func scrolltonextcell()
    {
        print("Current index:\(currentindex)")
        currentindex = currentindex + 1
        
        if currentindex <= imagearray.count-1
        {
            let indexPath = NSIndexPath(item: currentindex, section: 0) as IndexPath
            collectionview.scrollToItem(at: indexPath, at: .centeredHorizontally, animated: true)
            
            timer = Timer.scheduledTimer(timeInterval: 5.0, target: self, selector: #selector(IGStoryViewController.scrolltonextcell), userInfo: nil, repeats: false)
        }
        
    }

