2016-08-05 60 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。 –