更改UIImage上触摸部分的Alpha值?

时间:2013-09-20 07:27:29

标签: iphone ios ios5 ios6 ios6.1

如何将UIImage的alpha值更改为零,当我触摸它时,我只需要更改UIImage触摸部分的alpha值。

谁能帮帮我?

2 个答案:

答案 0 :(得分:1)

您可以使用UITapGestureRecognizer添加到UIImageView。首先,您需要将delaget添加到.h UIGestureRecognizerDelaget .h文件中。

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageTaped:)];
singleTap.numberOfTapsRequired = 1;
[self.imageview addGestureRecognizer:singleTap];

你还需要将 UserInterActionEnable 设置为yes,默认为no。

在这里做你想做的事

- (void)imageTaped:(UIGestureRecognizer *)gestureRecognizer 
{
    [UIView animateWithDuration:0.5 animations:^(void)
    {
         imageView.alpha = 0.0;
    }];
}

答案 1 :(得分:0)

请按照以下步骤操作。

  1. ImageView UserInteractionEnable应该是。
  2. 在ImageView上应用点按手势。
  3. 在tapGesture选择器中。将ImageView.alpha属性设为0。
  4. 如果你想为它设置动画,可以使用它。

    [UIView animateWithDuration:4.0 animations:^{
    
        ImageView.alpha = 0.0;
    }];
    
相关问题