- (void)viewDidLoad {
[super viewDidLoad];
image1=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"Default.png"]];
image1.frame=CGRectMake(0, 0, 320, 460);
image2=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"directoryPage.png"]];
image2.frame=CGRectMake(0, 0, 320, 480);
[self.navigationController setNavigationBarHidden:YES];
}
- (void)fade
{
image2.alpha = 0;
[self.view addSubview:image2];
// The upper layer will transition from alpha 1 to 0s
[self.view addSubview:image1];
BSheepAppDelegate *appD=(BSheepAppDelegate *)[[UIApplication sharedApplication]delegate];
if(appD.flag==0){
timer = [NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(fadeTimerEvent) userInfo:nil repeats:YES];
appD.flag=1;
}
else if (appD.flag==1) {
[self.view addSubview:image2];
image2.alpha=1;
}
}
// Rate of transition for alpha values
#define FADE_IN_RATE 1.0/100.0
#define FADE_OUT_RATE 2.0/200.0
- (void)fadeTimerEvent
{
if (image2.alpha >= 1)
{
// At this point, image2 is now visible
[timer invalidate];
timer = nil;
}
else
{
// Fade lower layer in (increase alpha)
image2.alpha += FADE_IN_RATE;
// Fade upper layer out (decrease alpha)
image1.alpha -= FADE_OUT_RATE;
}
}
используйте этот код для установки