2011-02-12 57 views
0

是否有可能具有紋理背景圖像和不透明度梯度的UIIView?即,bg圖像應該從背景容器視圖的左邊向右淡入。UIView不透明度梯度

感謝

+0

只需按照這篇文章的方向,你會算出它在30分鐘內最多: http://stackoverflow.com/questions/4977947/cagradientlayer-and-scrollviewtexturedbackgroundcolor/4978450#4978450 – greenhouse

回答

0

alpha通道(即PNG)保存您的背景圖像和做任何圖形應用程式使用褪色。

然後,把它作爲你的UIView的第一個孩子是一個UIImageView

0
- (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; 
    } 
} 

使用這個代碼來設置