开发者

put uiimages at the background

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 :/


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜