質問

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.

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top