将 uiimages 放在背景中

发布于 2024-11-18 11:50:18 字数 2910 浏览 2 评论 0原文

这是我的代码:

-(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];

 }

我想要的是将 imgViewimgView2 放在背景上,但只有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝戈者 2024-11-25 11:50:18

好的,最简单的方法是在屏幕上显示两个图像视图。因此,在 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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文