1

I have a couple of animations in my app that involve changing the alpha value of different objects. These work great for fading the object in, but they never seem to work for fading to 0.

        UIView.animateWithDuration(0.4,
            delay: 0,
            options: .CurveLinear & .AllowUserInteraction & .BeginFromCurrentState,
            animations: {
                cell.notesLabel.alpha = 0
            }, completion: nil)

Basically, the transparency just switches straight for 100% to 0% instantly. If I increase the duration, it just takes longer to start the animation and then it does it instantly again.

Anyone have any ideas?

Entire Code:

let cell = tableView.cellForRowAtIndexPath(indexPath) as CustomTransactionTableViewCell
        if cell.notesLabel.alpha == 100 {
            UIView.animateWithDuration(0.4,
                delay: 0,
                options: .CurveLinear | .AllowUserInteraction | .BeginFromCurrentState,
                animations: {
                    cell.notesLabel.alpha = 0
                }, completion: { (finished:Bool) in
                    UIView.animateWithDuration(1,
                        delay: 0,
                        options: .CurveLinear & .AllowUserInteraction & .BeginFromCurrentState,
                        animations: {
                            cell.paymentArrowImage.frame.origin.x = cell.paymentArrowImage.frame.origin.x - 400
                            cell.creditArrowImage.frame.origin.x = cell.creditArrowImage.frame.origin.x - 400
                            cell.paymentNameLabel.frame.origin.x = cell.paymentNameLabel.frame.origin.x + 400
                            cell.dateLabel.frame.origin.x = cell.dateLabel.frame.origin.x + 400
                            cell.costLabel.frame.origin.x = cell.costLabel.frame.origin.x - 400
                        }, completion: nil)
            })
        } else {
            UIView.animateWithDuration(0.4,
                delay: 0,
                options: .CurveLinear & .AllowUserInteraction & .BeginFromCurrentState,
                animations: {
                    cell.paymentArrowImage.frame.origin.x = cell.paymentArrowImage.frame.origin.x + 400
                    cell.creditArrowImage.frame.origin.x = cell.creditArrowImage.frame.origin.x + 400
                    cell.costLabel.frame.origin.x = cell.costLabel.frame.origin.x + 400
                    cell.paymentNameLabel.frame.origin.x = cell.paymentNameLabel.frame.origin.x - 400
                    cell.dateLabel.frame.origin.x = cell.dateLabel.frame.origin.x - 400
                    cell.notesLabel.alpha = 100
                }, completion: nil)
        }
user3746428
  • 11,047
  • 20
  • 81
  • 137

2 Answers2

2

Your options currently are .CurveLinear & .AllowUserInteraction & .BeginFromCurrentState

These options are actually bit-shifted values, so they are represented by 001, or 010, or 100, and so on.

When you & them together, you are actually testing to see which bits they all share in common. 001 % 010 returns 00, because where a 1 is found in one, a 0 is in the either.

What you want is to | (or) them together. This makes it so that if a 1 is found in that place value for any of the numbers, it is found in the answer. For example, 010 | 001 returns 011.

For your code, you really want .CurveLinear | .AllowUserInteraction | .BeginFromCurrentState.

erdekhayser
  • 6,537
  • 2
  • 37
  • 69
  • For some reason, that doesn't seem to fix it. I'll update my original question with the rest of my code so you can see if their is anything obvious wrong with it. – user3746428 Oct 17 '14 at 21:01
  • Although this doesn't fix the problem you reported, erdekhayser is still correct that this is a problem in your code. – Daniel T. Oct 18 '14 at 04:45
2

The problem is that you're using 0 to 100 as your alpha values, when they are expected to be values from 0.0 to 1.0. This is causing your condition to malfunction as well as causing the animation issues.

Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281