2014-02-21 37 views
0

我想使用渐变作为我的UIView的背景。UIView突出显示背景渐变

CAGradientLayer *gradientLayer = [[CAGradientLayer alloc] init]; 
    gradientLayer.frame = CGRectMake(0.f, 0.f, self.currencyView.frame.size.width, self.currencyView.frame.size.height); 
    [gradientLayer setLocations:@[@0.f, @1.f]]; 
    [gradientLayer setColors:@[(id)[UIColor whiteColor].CGColor,(id)[UIColor blackColor].CGColor]]; 
    [self.animalView.layer insertSublayer:gradientLayer atIndex:0]; 

我已经加入了UITapGestureRecognizer

UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showAnimalDetails)]; 
    [self.currencyView addGestureRecognizer:singleFingerTap]; 

我的问题是由这种观点可点击,我怎么可以添加一个突出梯度(可能只是扭转了梯度)当触摸了检测。

任何帮助将不胜感激。

+0

当您的视图被点击并设置为alpha时,更改一秒的alpha值.. :)可能会对您的情况有所帮助。 :) – iPatel

回答

0

使该图层成为类变量而不是本地图像,然后在showAnimalDetails函数内部根据需要更改渐变特性。然后致电setNeedsDisplay。尽管如此,你将不得不通过其他方式来处理取消选择。

+0

似乎没有工作:( – Neelesh

+0

@Neelesh而不是修改颜色,请尝试从self.layers中删除它,然后重新创建一个新的gradientLayer并将其添加到self.layers。 – Putz1103