这是我的代码:
-(void)transition
{
CATransition *applicationLoadViewIn = [CATransition animation];
[applicationLoadViewIn setDuration:2];
[applicationLoadViewIn setType:kCATransitionFade];
[applicationLoadViewIn setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn]];
//on ajoute l animation au layer
[[self.view layer] addAnimation:applicationLoadViewIn forKey:kCATransitionFade];
//On configure notre nouvel image
int rand = arc4random() % 6;
switch (rand) {
case 0:
imgView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pinkfont.png"]];
break;
case 1:
imgView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"greenfont.png"]];
break;
case 2:
imgView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"whitefont.png"]];
break;
case 3:
imgView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yellowfont.png"]];
break;
case 4:
imgView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"purplefont.png"]];
break;
case 5:
imgView2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bluefont.png"]];
break;
}
/
if(self.view.layer.sublayers.count<=2)
//premier cas on ajoute notre image
{
[[[self view] layer] addSublayer:[imgView2 layer]];
[self.view sendSubviewToBack:imgView2];
}
else {
//deuxieme cas on supprime notre image
[[self.view.layer.sublayers lastObject] removeFromSuperlayer];
}
[imgView2 release];
}
- (void)viewDidLoad {
[super viewDidLoad];
UIImage *image2 = [UIImage imageNamed:@"belleouf2_03.png"];
int rand2 = arc4random() % 5;
switch (rand2) {
case 0:
imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"pinkfont.png"]];
break;
case 1:
imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"greenfont.png"]];
break;
case 2:
imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"whitefont.png"]];
break;
case 3:
imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yellowfont.png"]];
break;
case 4:
imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"purplefont.png"]];
break;
case 5:
imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bluefont.png"]];
break;
}
//On ajoute à la vue le layer avec notre image
[[[self view] layer] addSublayer:[imgView layer]];
[self.view sendSubviewToBack:imgView];
[imgView release];
[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(transition) userInfo:nil repeats:YES];
}
我想要的是将imgView
和imgView2
放在后台,但只有imgView
位于后台,而且只在开头(viewDidLoad
)。我该怎么办?对不起我的英语我是法国人:/
答案 0 :(得分:0)
好的最简单的方法是在屏幕上显示两个图像视图。因此,在Interface Builder中,您将在底部显示最后显示的图像。让它们全部堆叠在一起。然后使用NSTimer将图像视图设置为不可见。因此,如果将顶层设置为不可见,则第二个图像将变为可见,然后使第一个图像返回,将顶部图像设置回可见,并且由于该图像位于顶部,因此它将显示为背景。希望这可以帮助!