点按即可更改UIImageView alpha状态

时间:2013-05-06 21:40:05

标签: ios gesture alpha tap

希望通过点击手势更改UIimageview alpha,例如:

点按 - 将alpha更改为0.5f
再次点按 - alpha返回1状态

有可能吗?

1 个答案:

答案 0 :(得分:6)

将点按手势识别器附加到视图:

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(yourFunction:)];
[imageView addGestureRecognizer:tap];

然后在手势识别器的处理程序中:

if (imageView.alpha > 0.5f){
    imageView.alpha = 0.5f;
}
else {
    imageView.alpha = 1.0;
}