Question

I am trying add subview with animation effect using the code which work fine for the first time below.

CATransition *transition = [CATransition animation];
transition.duration = 1.0;
transition.type = kCATransitionMoveIn; 
transition.subtype = kCATransitionFromRight;

[newView.layer removeAllAnimations]
[newView.layer addAnimation:transition forKey:nil];
[self.masterview addSubview:newView];

There is a back button in newView which removes the View from the superview.

[newView removeFromSuperview];

Now when I try adding newView as subview again using the above code,its first adds the view as a subview(without animation) and again with animation.

Was it helpful?

Solution

Instead of removing newView from superview, why not you can just set a frame like

newView.frame = CGRectMake(0, -500, CGRectGetWidth(newView.frame), CGRectGetHeight(newView.frame));

so that you can just hide it from showing. Just an idea. :-)

OTHER TIPS

When you remove the view from its super view it keeps its frame as it is. So, i think you have to change the newView location to be placed in the new location again.

It will work fine for all the times.But the only difference you have to find is that you need to wai for the duration of animation. It will not animate continuously. It will take a minimum time that you mentioned in the duration.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top