2012-12-28 81 views
2

我正在制作移动触摸项目我想在触摸位置更改图像的alpha或可见性(无论可能)。让我们说Unhidethat特定点的图片..如何更改UIImageView alpha onTouchMoved

PS我已经知道如何擦除图像。我正在寻找unerase

+0

你有没有解决这个问题? – Spynet

+0

是的,我得到它我正打算解决它改变阿尔法或unerase方式但你救了我...... 我不认为所以我得到任何有关的,直到一天,我可以帮助,所以我会这样做在prev的方式你告诉我 –

+0

享受继续发布查询 – Spynet

回答

0

我相信阿尔法是整个视图的属性,所以你所能做的就是绘制该特定点...请参阅这可能是this是你想要实现的。

+0

感谢Ankit但我想隐藏隐藏 –

0
- (void)viewDidLoad 
{ 
    //load super view 
    [super viewDidLoad]; 

    //to decrease alpha. 
    UISwipeGestureRecognizer *swiperight=[[UISwipeGestureRecognizer alloc]  
    initWithTarget:self action: @selector(setalpha_decrease:)]; 
    [swiperight setDirection:UISwipeGestureRecognizerDirectionRight]; 
    [self.view addGestureRecognizer:swiperight]; 

    //to increase alpha.  
    UISwipeGestureRecognizer *swipeleft=[[UISwipeGestureRecognizer alloc] 
    initWithTarget:self action: @selector(setalpha_increase:)]; 
    [swipeleft setDirection:UISwipeGestureRecognizerDirectionLeft]; 
    [self.view addGestureRecognizer:swipeleft]; 



    } 


    -(void) setalpha_decrease:(UIPanGestureRecognizer *) gestureRecognizer { 

    imgview.alpha= imgtomove.alpha-(imgtomove.alpha/10); 
    } 



    -(void) setalpha_increase:(UIPanGestureRecognizer *) gestureRecognizer { 

    imgview.alpha= imgtomove.alpha+(imgtomove.alpha/10); 

    } 
-1
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    UITouch *t = [[touches allObjects] objectAtIndex:0]; 
    float alpha = [t locationInView:self.view].x/self.view.frame.size.width; 
    _img.alpha = alpha; 
} 
0

你为什么不把它填充了一种颜色或纹理,然后使用@AnkitSrivastava回答让触摸去擦视图的背景部分顶部空视图,揭示隐藏的图像背后。

1

我不具有对代码的好形式,因为他们是从我的博客复制抱歉。 编辑需要我很多。

1隐藏您触摸的部分。

当你的手指移动,删除某些部分:

- (UIImage *)erasePartsMoved { 
UIImage *image = nil; 
UIColor *color = [UIColor whiteColor]; 
CGFloat width = 5.0f; 
CGSize imageContextSize = self.imageView.frame.size; 

UIGraphicsBeginImageContext(imageContextSize); 

CGContextRef context = UIGraphicsGetCurrentContext(); 

CGContextSetLineWidth(context, width); 
CGContextSetStrokeColorWithColor(context, [color CGColor]); 

CGContextMoveToPoint(context, self.touchStartPoint.x, self.touchStartPoint.y); 
//Do something needed. 
CGContextAddLineToPoint(context, self.touchEndPoint.x, self.touchEndPoint.y); 

CGContextStrokePath(context); 

image = UIGraphicsGetImageFromCurrentImageContext(); 

UIGraphicsEndImageContext(); 
return image;} 

2您的图片是不可见的,在第一,例如,透明。

得到点触摸,则计算与触摸点了一圈,终于改变像素中圈阿尔法:

typedef struct _singleRGBA{ 
unsigned char red; 
unsigned char green; 
unsigned char blue; 
unsigned char alpha;} RGBA; 

要改变像素的Alpha:

void filterOpacity(UInt8 *pixelBuf, UInt32 offset, void *context){ 
double val = *((double*)context); 
int a = offset+3; 
int alpha = pixelBuf[a]; 
pixelBuf[a] = SAFECOLOR(alpha * val);} 

我希望以上会帮忙。 有趣的问题,我想稍后做一个可运行的演示。