Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UICollectionView无限滚动跳跃效果_Ios_Objective C_Swift_Jsqmessagesviewcontroller - Fatal编程技术网

Ios UICollectionView无限滚动跳跃效果

Ios UICollectionView无限滚动跳跃效果,ios,objective-c,swift,jsqmessagesviewcontroller,Ios,Objective C,Swift,Jsqmessagesviewcontroller,我正在制作一个messenger应用程序,比如telegram,我想实现一个无限滚动,我使用JSQMessageViewController进行聊天 这是无限滚动的代码: override func scrollViewDidScroll(scrollView: UIScrollView) { if(scrollView.contentOffset.y >= 0.0 && scrollView.contentOffset.y <= 30.0 &&

我正在制作一个messenger应用程序,比如telegram,我想实现一个无限滚动,我使用
JSQMessageViewController
进行聊天

这是无限滚动的代码:

 override func scrollViewDidScroll(scrollView: UIScrollView) {
   if(scrollView.contentOffset.y >= 0.0 && scrollView.contentOffset.y <= 30.0 && loading == true){
        self.loading = false
        self.loadMore()
    }
}
覆盖函数scrollViewDidScroll(scrollView:UIScrollView){

如果(scrollView.contentOffset.y>=0.0&&scrollView.contentOffset.y)Luca Becchetti,您已经解决了这个问题吗?
func loadMore() {

            //Controllo se nell'array sono presenti altri messaggi
            if ((chatList?.messages.count)!-1) != self.messages.count{
               //
                CATransaction.begin()
                CATransaction.setDisableActions(true)

                let oldBottomOffset = self.collectionView!.contentSize.height - self.collectionView!.contentOffset.y
                UIView.performWithoutAnimation({ () -> Void in


                self.collectionView!.performBatchUpdates({ () -> Void in

                    let idInit = (self.lastMessageId-self.messagePerPage<0) ? 0 : self.lastMessageId-1-self.messagePerPage
                    let idEnd  = self.lastMessageId-1

                    var indexPaths: [NSIndexPath] = []
                    for(var i = 0; i<idEnd-idInit; i++){
                        print("Creo indexpath \(i)")
                        indexPaths.append(NSIndexPath(forItem: i, inSection: 0))
                    }

                    self.collectionView!.insertItemsAtIndexPaths(indexPaths)

                    let msg = self.chatList?.messages
                    var i = idEnd
                    repeat {
                        let mg = msg![i]
                        let messagechat:JSQMessage = JSQMessage(senderId: mg.sender, senderDisplayName: "", date:mg.time, text: mg.message)
                        messagechat.xmppMessageID = mg.messageID
                        messagechat.status        = mg.messageStatus
                        self.messages.insert(messagechat, atIndex: 0)
                        self.lastMessageId = i
                        i--
                    } while i > idInit

                    // invalidate layout
                    self.collectionView!.collectionViewLayout.invalidateLayoutWithContext(JSQMessagesCollectionViewFlowLayoutInvalidationContext())

                    }, completion: {(finished) in

                        //scroll back to current position
                        self.finishReceivingMessageAnimated(false)
                        self.collectionView!.layoutIfNeeded()
                        self.collectionView!.contentOffset = CGPointMake(0, self.collectionView!.contentSize.height - oldBottomOffset)
                        CATransaction.commit()


                })
                     })
            }
            else {

                print("No more messages to load.")
            }


}