iOS:使用手势更改图像视图的alpha
我想用像上下或左右这样的手势来改变图像的alpha值。 我不想用滑块来做这个 是否可以这样做?如果可以,请告诉我如何或我必须使用滑块iOS:使用手势更改图像视图的alpha,ios,objective-c,uiimageview,uigesturerecognizer,alpha,Ios,Objective C,Uiimageview,Uigesturerecognizer,Alpha,我想用像上下或左右这样的手势来改变图像的alpha值。 我不想用滑块来做这个 是否可以这样做?如果可以,请告诉我如何或我必须使用滑块 谢谢。尝试执行以下操作: 首先连接轻触手势识别器以查看: UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(yourTapMethod:)]; tap.numberOfTapsRequired = 1; tap.num
谢谢。尝试执行以下操作: 首先连接轻触手势识别器以查看:
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(yourTapMethod:)];
tap.numberOfTapsRequired = 1;
tap.numberOfTouchesRequired = 1;
[imageView addGestureRecognizer:tap];
然后,在手势识别器处理程序中执行以下操作:
-(void)yourTapMethod{
[UIView animateWithDuration:0.5 animations:^(void){
imageView.alpha = //add any value (like 0.2f);
}
您可以在视图或视图控制器上实现方法
-(无效)触摸移动:(NSSet*)触摸事件:(UIEvent*)事件
{
UITouch*touch=[触摸任何对象];
CGPoint位置=[触摸位置查看:自];
NSLog(@“位置:%@”,NSStringFromCGPoint(位置));
//例如:
//alpha取决于与视图边界宽度相关的位置.x
CGFloat alpha=(self.bounds.size.width-location.x)/self.bounds.size.width;
NSLog(@“alpha:%@,@(alpha));
}
您可以在其中检查
location.x
或location.y
我知道如何将手势应用于视图,但我想更改图像视图的alpha,就像使用滑块更改一样。在我的情况下,我不想使用滑块,你看过应用程序Prisma吗?我想改变alpha,就像在图像视图中那样。