0
votes

I have an UIView that contains two UIImageView (one is a cartoon, the other one its special shadow). "self" is the UIView object.

On tap I want to remove the UIView from its superview via a curl effect. This works very fine.

But before it is curled up, I want to remove my custom made shadow UIImageView, so that my shadow doesn't curl together with the curl effect shadow. Removing the UIImageView from the UIView right BEFORE the animation just does not work.

My code:

[myShadow setImage:nil];

[UIView transitionWithView:self duration:1.0
 options:UIViewAnimationOptionTransitionCurlUp
 animations:^ { [self setHidden:YES];}
 completion:nil];

This doesn't remove myShadow. When I comment out the transitionWithView myShadow is removed just fine, but - of course- there is no animation following.

With the animation following the setImage:nil doesn't show any effect. I also tried [myShadow removeFromSuperview] and [myShadow release], also didn't do anything.

I was trying a lot of things and googling for over 3 hours. For example I tried

[self setNeedsDisplay];

or

 animations:^ { [myShadow setImage:nil]; [self setHidden:YES];}

I played with this, but didn't get myShadow to disappear before the animation.

What can I do? Thank you.

1
I doubt whether it works on iOS 4Praveen-K

1 Answers

3
votes

I would try this when removing the shadow:

[ CATransaction begin ];
[ CATransaction setValue: [ NSNumber numberWithBool: YES ] 
        forKey: kCATransactionDisableActions ];
[ myShadow setImage: nil ];
[ CATransaction commit ];

[ UIView transitionWithView: self 
        duration: 1.0 
        options: UIViewAnimationOptionTransitionCurlUp
        animations: ^ { [ self setHidden: YES ]; }
        completion: nil ];

That should avoid any issue with the shadow animating away while the transition is happening. If that still does not work then you could try to add this after setting the shadow image to nil:

[ self displayIfNeeded ];

This is instead of [ self setNeedsDisplay ]. setNeedsDisplay does not cause anything to happen immediately but rather just marks the view as needing display, which will happen later. displayIfNeeded will cause the view to draw immediately.

It it possible that just changing setNeedsDisplay to displayIfNeeded will be all you need to do.