2016-08-05 55 views

回答

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.xlocation.y

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); 
    } 
+0

我知道如何将手势应用于视图,但我想更改图像视图的alpha值,就像我们使用滑块更改一样。在我的情况下,我不想使用滑块那 –

+0

看到更新的答案@Bhagyashreemahajan –

+0

你有没有看到应用Prisma?我想要像图像视图手势那样更改alpha。 –