我正在制作移动触摸项目我想在触摸位置更改图像的alpha或可见性(无论可能)。让我们说Unhidethat特定点的图片..如何更改UIImageView alpha onTouchMoved
PS我已经知道如何擦除图像。我正在寻找unerase
我正在制作移动触摸项目我想在触摸位置更改图像的alpha或可见性(无论可能)。让我们说Unhidethat特定点的图片..如何更改UIImageView alpha onTouchMoved
PS我已经知道如何擦除图像。我正在寻找unerase
我认为这个项目确实你在寻找什么:https://github.com/SebastienThiebaud/STScratchView
你有2个图像,其中一个是隐藏的图像,另一个就是你刮开一个。
甚至这个项目:http://www.cocoacontrols.com/platforms/ios/controls/scratch-n-see
- (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);
}
-(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;
}
你为什么不把它填充了一种颜色或纹理,然后使用@AnkitSrivastava回答让触摸去擦视图的背景部分顶部空视图,揭示隐藏的图像背后。
我不具有对代码的好形式,因为他们是从我的博客复制抱歉。 编辑需要我很多。
当你的手指移动,删除某些部分:
- (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;}
得到点触摸,则计算与触摸点了一圈,终于改变像素中圈阿尔法:
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);}
我希望以上会帮忙。 有趣的问题,我想稍后做一个可运行的演示。
你有没有解决这个问题? – Spynet
是的,我得到它我正打算解决它改变阿尔法或unerase方式但你救了我...... 我不认为所以我得到任何有关的,直到一天,我可以帮助,所以我会这样做在prev的方式你告诉我 –
享受继续发布查询 – Spynet