问题
I'm trying to do a flip transition between a view, A-1, and a backside view, A-2, using UIView.transitionFromView:toView:. These views have a number of siblings, and since I don't want the entire superview to rotate, I insert a temporary container view that's just large enough to contain both A-1 and A-2 into the view hierarchy and insert A-1 into that immediately prior to the transition.
The problem is that view A-1 disappears with an unsightly flash as soon as the transition starts, which is ugly. I thought it might be disappearing when I insert it into the temporary container view (since adding it to the container implicitly removes it from its normal superview), but as best I can tell, it isn't happening at that point. The code I'm using looks something like this:
[container addSubview:fromView];
[self.view addSubview:container];
[UIView transitionFromView:fromView toView:toView duration:2
options:UIViewAnimationOptionTransitionFlipFromRight
... ];
I unhook and remove the container in the completion routine, which I'm not showing here as the flash problem occurs before that code gets executed.
Do I have to do this at the CALayer level to avoid this problem? Am I misunderstanding something about how view-to-view transitions are supposed to work? Any thoughts would be appreciated, Howard
回答1:
Got it! I should have known, as I've been bitten by this in the past (and foolishly thought I'd never make the same mistake again. :-) It's all about that magic "redraw moment" thing -- after inserting the temporary container into the hierarchy and moving the 'fromView' into the container, you need to call
[self performSelector:@selector(doAnimation:) withObject:transitionInfo afterDelay(0)]
to get back to the main runloop so that the updated hierarchy can redraw itself before you actually do the animation. The 'transitionInfo' argument is just a dictionary for passing the 'fromView' and 'toView' arguments to the animation routine.
Howard
来源:https://stackoverflow.com/questions/12642847/annoying-flash-on-uiview-flip-transition