segmented controls mangled during initial transition animation
- by dLux
greetings and salutations folks, i'm relatively new to objective c & iphone programming, so bare with me if i've overlooked something obvious..
i created a simple app to play with the different transition animations, setting up a couple segmented controls and a slider..
(Flip/Curl),
(left/right) | (up/down),
(EaseInOut/EaseIn/EaseOut/Linear)
i created a view controller class, and the super view controller switches between 2 instances of the sub class.
as you can see from the following image, the first time switching to the 2nd instance, while the animation is occurring the segmented controls are mangled; i'd guess they haven't had enuff time to draw themselves completely..
http://img689.imageshack.us/img689/2320/mangledbuttonsduringtra.png
they're fine once the animation is done, and any subsequent times..
if i specify cache:NO in the setAnimationTransition it helps, but there still seems to be some sort of progressive reveal for the text in the segmented controls; they still don't seem to be pre-rendered or initialized properly.. (and surely there's a way to do this while caching the view being transitioned to, since in this case the view isn't changing and should be cacheable.)
i'm building my code based on a couple tutorials from a book, so i updated the didReceiveMemoryWarning to set the instanced view controllers to nil; when i invoke a memory warning in the simulator, i assume it's purging the other view, and it acts like a first transition after loading, the view being transitioned to appears just like the image above..
i guess it can't hurt to include the code (sorry if it's considered spamming), this is basically half of it, with a similar chunk following this in an else statement, for the case of the 2nd side being present, switching back to the 1st..:
- (IBAction)switchViews:(id)sender
{
[UIView beginAnimations:@"Transition Animation" context:nil];
if (self.sideBViewController.view.superview == nil) // sideA is active, sideB is coming
{
if (self.sideBViewController == nil)
{
SideAViewController *sBController =
[[SideAViewController alloc] initWithNibName:@"SideAViewController" bundle:nil];
self.sideBViewController = sBController;
[sBController release];
}
[UIView setAnimationDuration:sideAViewController.transitionDurationSlider.value];
if ([sideAViewController.transitionAnimation selectedSegmentIndex] == 0)
{
// flip: 0 == left, 1 == right
if ([sideAViewController.flipDirection selectedSegmentIndex] == 0)
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft
forView:self.view
cache:YES];
else
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight
forView:self.view
cache:YES];
}
else
{
// curl: 0 == up, 1 == down
if ([sideAViewController.curlDirection selectedSegmentIndex] == 0)
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp
forView:self.view
cache:YES];
else
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown
forView:self.view
cache:YES];
}
if ([sideAViewController.animationCurve selectedSegmentIndex] == 0)
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
else if ([sideAViewController.animationCurve selectedSegmentIndex] == 1)
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
else if ([sideAViewController.animationCurve selectedSegmentIndex] == 2)
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
else if ([sideAViewController.animationCurve selectedSegmentIndex] == 3)
[UIView setAnimationCurve:UIViewAnimationCurveLinear];
[sideBViewController viewWillAppear:YES];
[sideAViewController viewWillDisappear:YES];
[sideAViewController.view removeFromSuperview];
[self.view insertSubview:sideBViewController.view atIndex:0];
[sideBViewController viewDidAppear:YES];
[sideAViewController viewDidDisappear:YES];
}
any other tips or pointers about writing good clean code is also appreciated, i realize i still have a lot to learn..
thank u for ur time,
-- d