Currently I am having a issue switching views using Core Animation. I want to fade through black switching to my next view. Right now it does not do anything besides lose touch events from my original view. What am I doing wrong in the code below?
Edit1 Code:
- (void)changeView1ToView2 {
CABasicAnimation *fadeout= [CABasicAnimation animationWithKeyPath:@"opacity"];
[fadeout setDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:)];
[fadeout setToValue:[NSNumber numberWithFloat:0]];
[fadeout setDuration:0.5];
[[self.view layer] addAnimation:fadeout forKey:@"alpha"];
}
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag {
[self.view addSubview:self.view2.view];
self.view2.view.frame = [UIScreen mainScreen].bounds;
[self.view2.view setAlpha:0];
CABasicAnimation *fadein = [CABasicAnimation animationWithKeyPath:@"opacity"];
[fadein setToValue:[NSNumber numberWithFloat:1.0]];
[fadein setDuration:0.5];
[[self.view2.view layer] addAnimation:fadein forKey:@"alpha"];
}
Ok I added self, look at my new code above. view2 is a UIViewController, thats why I am doing .view after it. The app is only going to be available on iOS 5 or up so thats not a problem. But what I am trying to achieve is switching views using Core Animation, and have each UIViewController manage their own views. I am just switching views using Core Animation instead of usual means.
view2a member ofself, in this case? Should it be a property, alaself.view2…? This is probably unrelated to your issue, but if you have a property for this member, you should use the accessors wherever possible.- (void) deallocand anyinitmethods being the exception.view2is actually aUIViewControllersubclass? It looks like it, based on the syntax. If you're targeting iOS4 or earlier, it's not a good idea to have multiple view controllers sharing the sameUIView. Under iOS5, you can have multiple view controllers sharing parts of the view hierarchy, but you should be using the view controller container methods onselfto add them, assumingselfis also aUIViewController.