开发者

Implementing iFog like app - Revealing inner UIImage

I'm trying to implement iFog like view, meaning a view when you can smear-like your finger on the screen and it will reveal what's beneath.

I have two problems with what I did so far:

  1. When I first touch the screen, instead of revealing what's beneath in a circle, it shows the entire black rect. Next touches on screen work as expected.

  2. When I scroll the mouse fast- not even that fast actually (still testing on simulator) - it doesn't seem to handle it well, as you can see by the gaps between the circles in the below picture. Maybe is has to do with improving the performance of what I did.

Picture attached to illustrate the black rect and the gaps.

Implementing iFog like app - Revealing inner UIImage

My Code: (UIView Subclass) Basically I'm showing the first image, and then revealing second image by traveling with my finger on screen.

- (void)drawRect:(CGRect)rect
{

    if (didStartTouching)
    {

        CGContextRef contextRef = UIGraphicsGetCurrentContext();    

        CGContextAddArc(contextRef, rect.origin.x+CIRCLE_RADIUS, rect.origin.y+CIRCLE_RADIUS, CIRCLE_RADIUS, 0, 360, 0);           开发者_如何学Go 

        CGContextClip(contextRef);

        UIImage* img = [UIImage imageNamed:@"apple"];

        [img drawInRect:CGRectMake(0, 0, img.size.width, img.size.height)];    


    }
    else
    {
        UIImage* img = [UIImage imageNamed:@"default_pic_1"];

        [img drawInRect:CGRectMake(0, 0, img.size.width, img.size.height)];            
    }

}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{

    [self revealImageInSet:touches];
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{

    [self revealImageInSet:touches];    
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{

    [self revealImageInSet:touches];
}

-(void) revealImageInSet:(NSSet*)touches
{
    didStartTouching = YES;

    UITouch *touch = [touches anyObject];

    CGPoint point = [touch locationInView:self];     

    CGRect rect = CGRectMake(point.x-CIRCLE_RADIUS, point.y-CIRCLE_RADIUS, CIRCLE_RADIUS*2, CIRCLE_RADIUS*2);

    [self setNeedsDisplayInRect:rect];

}


Instead of revealing the image only on the place where you got touches, you should reveal the image from your last touch point to your current touch point. Like making a line from the last touch to the current touch, then reveal whatever is behind that area. that would make it smoother.

Got no idea on the black rect on the first touch, sorry.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜