我想用上下或左右手势改变图像的alpha值。 我不想使用滑块。
是否可以这样做,如果是,那么请告诉我如何或我必须使用滑块?
谢谢。
答案 0 :(得分:0)
尝试执行以下操作:
首先点按GestureRecognizer
以查看:
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);
}
答案 1 :(得分:0)
您可以在视图或视图控制器上实现方法
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self];
NSLog(@"location: %@",NSStringFromCGPoint(location));
// Example:
// alpha depends on location.x related to view bounds width
CGFloat alpha = (self.bounds.size.width - location.x) / self.bounds.size.width;
NSLog(@"alpha: %@",@(alpha));
}
您可以在其中查看location.x
或location.y
。