将 uiimages 放在背景中
这是我的代码:
-(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
)。请问我该怎么做?抱歉我的英语我是法国人:/
here is my code :
-(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];
}
what I want is to put imgView
and imgView2
at the background, but there is only imgView
which is at the background and this only at the beginning(viewDidLoad
). How can I do this please ? sorry for my english I'm french :/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,最简单的方法是在屏幕上显示两个图像视图。因此,在 Interface Builder 中,您将最后在底部显示图像。将它们全部堆叠在一起。然后使用 NSTimer 将图像视图设置为不可见。因此,如果将顶层设置为不可见,则第二个图像将变得可见,然后为了使第一个图像返回,请将顶部图像设置回可见,并且由于该图像位于顶部,因此它将显示为背景。希望这有帮助!
Ok the easiest way to do this is to have two image views on the screen. So in Interface Builder have the image you will show last on the bottom. Have them all stacked on top of each other. Then use your NSTimer to set a image view to not visible. So if you set the top layer as invisible the second image will become visible and then to make the first image come back, set the top image back to visible and since that image is on the top, it will appear as the background. Hope this helps!