K
K
KVS172016-01-18 15:52:05
Swift
KVS17, 2016-01-18 15:52:05

Display collectionView bottom-up (uphill)?

The controller must display data from the bottom up, which is what it actually does. Implemented like this

override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.collectionView!.transform = CGAffineTransformMake(1, 0, 0, -1, 0, 0)
        takeTotalMessages()
        
    }

The cells are also transformed by transform
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! ChatCollectionViewCell
        cell.transform=self.collectionView!.transform

        let message = dataSource[indexPath.row]
        
        cell.nameNick?.text = message.nickname
        cell.textMess?.text = message.text
        
        return cell
    }

Description of ChatCollectionViewCell
class ChatCollectionViewCell: UICollectionViewCell {
    
    @IBOutlet weak var nameNick: UILabel?
    @IBOutlet weak var textMess: UILabel?
        
}

The problem is that when the first data is displayed, cell.transform=self.collectionView!.transform does not work and the data is turned upside down at startup, it is displayed as on the screenshot, if you scroll up and return to the original place, then everything is as it should. Yes, and the new data that is loaded is displayed as it should, the problem is only in displaying the first data.
7222940048ec45b8a1eef7e909db84be.gif

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
ManWithBear, 2016-01-18
@ManWithBear

What do you want to achieve?

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];
  [self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:lastRow inSection:lastSection] atScrollPosition: UICollectionViewScrollPositionBottom animated:NO];
}

UPD2. If you still want to do meaningless transformations, then do it in
- collectionView:willDisplayCell:forItemAtIndexPath:

E
Evgeny Elchev, 2016-01-18
@rsi

First, I join the ManWithBear question , but let's play telepaths. Apparently you flipped the collectionView to add new cells to the top of the table, and they appeared at the bottom, this is an extremely bad decision.
Secondly, this `cell.transform=self.collectionView!.transform` is best done not in `cellForItemAtIndexPath ` in the `ChatCollectionViewCell` class, you just created it that way, right.
Third, make a constant `let transform = CGAffineTransformMake(1, 0, 0, -1, 0, 0)` and assign it to `self.collectionView!.transform = transform ` and `cell.transform=transform `

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question