Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

grandM

macrumors 68000
Original poster
Oct 14, 2013
1,539
304
So I'm panning cells in a collection view. The cells are wiggling. I'm using following code to re-order the cells in my dataSet. Everything works out. The only problem I have is that the panned cell sometimes stops wiggling. I noticed this happens when I pan too fast, just throwing it to another place. I looked on the internet. Some people advise using invalidatelayout(). Unfortunately this isn't helping. Does anyone know what could help? Tx.
Code:
func panningMediaInMediaCollectionView(gesture: UIPanGestureRecognizer) {
      
        switch(gesture.state){

        case .Began:

            guard let selectedIndexPath = self.mediaCollectionView.indexPathForItemAtPoint(gesture.locationInView(self.mediaCollectionView)) else {break}

            self.mediaCollectionView.beginInteractiveMovementForItemAtIndexPath(selectedIndexPath)


        case .Changed:

            self.mediaCollectionView.updateInteractiveMovementTargetPosition(gesture.locationInView(self.mediaCollectionView))


        case .Cancelled:

            self.mediaCollectionView.cancelInteractiveMovement()


        case .Ended:

            self.mediaCollectionView.endInteractiveMovement()

            self.mediaCollectionView.collectionViewLayout.invalidateLayout()


        default:

            self.mediaCollectionView.cancelInteractiveMovement()

        }

    }
 
It would be helpful to see what the functions performing the animations are actually doing, can you post those functions? Are you using Core Animation?
 
It would be helpful to see what the functions performing the animations are actually doing, can you post those functions? Are you using Core Animation?
I'm no expert in animation. I barely know the basics about it. I'm using following code:
Code:
func animateZoomCell() {

        UIView.animateKeyframesWithDuration(0.1, delay: 0, options: UIViewKeyframeAnimationOptions.AllowUserInteraction, animations: { () -> Voidin

            self.transform = CGAffineTransformMakeScale(1.1, 1.1)

            }) { (completed) -> Voidin

                self.transform = CGAffineTransformMakeScale(1.0, 1.0)

        }

    }

   

    func wobble(){


        let animationRotateDegres: CGFloat = 0.5

        let animationTranslateX: CGFloat = 1.0

        let animationTranslateY: CGFloat = 1.0

        let count: Int = 1

       

       

        let leftOrRight: CGFloat = (count % 2 == 0 ? 1 : -1)

        let rightOrLeft: CGFloat = (count % 2 == 0 ? -1 : 1)

        let leftWobble: CGAffineTransform = CGAffineTransformMakeRotation(degreesToRadians(animationRotateDegres * leftOrRight))

        let rightWobble: CGAffineTransform = CGAffineTransformMakeRotation(degreesToRadians(animationRotateDegres * rightOrLeft))

        let moveTransform: CGAffineTransform = CGAffineTransformTranslate(leftWobble, -animationTranslateX, -animationTranslateY)

        let conCatTransform: CGAffineTransform = CGAffineTransformConcat(leftWobble, moveTransform)

       

        transform = rightWobble // starting point

       

        UIView.animateWithDuration(0.1, delay: 0.08, options: [.AllowUserInteraction, .Repeat, .Autoreverse], animations: { () -> Voidin

            self.transform = conCatTransform

            }, completion: nil)

    }

   

    func stopWobbling(){

        self.layer.removeAllAnimations()

    }
 
If you use print statements are the animations getting called when they should? Try it with just a single cell to isolate the problem.

If it is being called at the right time, is it being called on the main thread?

Problems like this are why I use Core Animation for most purposes, you will definitely want to learn how to use it manually.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.