Make that layer a class variable instead of local, then inside your showAnimalDetails
function change the gradient properties however you wish. Then call setNeedsDisplay
. You are going to have to deal with deselection by other means though.
UIView highlighted background gradient
-
14-10-2022 - |
質問
I am trying to use a gradient as a background to my 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];
I have made this view tappable by adding a UITapGestureRecognizer
UITapGestureRecognizer *singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showAnimalDetails)];
[self.currencyView addGestureRecognizer:singleFingerTap];
My question is, how can I add a highlighted gradient (possibly just reversing the gradient) when the touch was detected.
Any help would be greatly appreciated.
解決
所属していません StackOverflow