大佬教程收集整理的这篇文章主要介绍了ios – 如何使用GraphicContext在Objective C中获得逐渐变细的线条效果,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { mouseSwiped = YES; UITouch *touch = [touches anyObject]; currentPoint = [touch LOCATIOnInView:self.view]; UIGraphicsBeginImageContext(CGSizeMake(320,568)); [drawImage.image drawInRect:CGRectMake(0,320,568)]; CGContextSetLineCap(UIGraphicsGetCurrentContext(),kCGLineCapRound); CGContextSetLineWidth(UIGraphicsGetCurrentContext(),5.0); CGContextSetRGBstrokeColor(UIGraphicsGetCurrentContext(),1); CGContextBeginPath(UIGraphicsGetCurrentContext()); CGContextMoveToPoint(UIGraphicsGetCurrentContext(),lastPoint.x,lastPoint.y); CGContextAddLineToPoint(UIGraphicsGetCurrentContext(),currentPoint.x,currentPoint.y); CGContextstrokePath(UIGraphicsGetCurrentContext()); [drawImage setFrame:CGRectMake(0,568)]; drawImage.image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); lastPoint = currentPoint; } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { //what code do I put here to get the flick effect - what CGGetContext Parameter //may be applicable or what progrAMMing technique may Help with this. }
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { //what code do I put here to get the flick effect - what CGGetContext Parameter //may be applicable or what progrAMMing technique may Help with this. UIGraphicsBeginImageContext(CGSizeMake(320,568)); [drawImage.image drawInRect:CGRectMake(0,568)]; CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetLineWidth(context,5.0); CGContextSetRGBFillColor(context,1); CGContextBeginPath(context); CGContextBeginPath(context); CGContextMoveToPoint(context,lastPoint.y); CGContextAddLineToPoint(context,currentPoint.y); CGContextClosePath(context); CGContextstrokePath(context); //Normalized directionality float lineLength = sqrt((currentPoint.x - lastPoint.X)*(currentPoint.x - lastPoint.X) + (currentPoint.y - lastPoint.y)*(currentPoint.y - lastPoint.y)); float dx = (currentPoint.x - lastPoint.X)/lineLength; float dy = (currentPoint.y - lastPoint.y)/lineLength; //Now make a triangle CGContextBeginPath(context); //2.5 is from 1/2 of your line width (5) CGContextMoveToPoint(context,currentPoint.x + 2.5*dy,currentPoint.y - 2.5*dX); //This 10 is completely arbitrary,the length your taper is going to be. //Ideally this will be proportional to your last line segment length,longer if their finger is moving faster... CGContextAddLineToPoint(context,currentPoint.x + 10*dx,currentPoint.y + 10*dy); //Now the last tip of the triangle CGContextMoveToPoint(context,currentPoint.x - 2.5*dy,currentPoint.y + 2.5*dX); CGContextClosePath(context); CGContextFillPath(context); [drawImage setFrame:CGRectMake(0,568)]; drawImage.image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); }
现在为了制作这个散热器,您可以添加人物绘制的曲线计算,并在弯曲的方向上创建具有贝塞尔曲线的“三角形”锥形.这实际上可能非常有趣.
以上是大佬教程为你收集整理的ios – 如何使用GraphicContext在Objective C中获得逐渐变细的线条效果全部内容,希望文章能够帮你解决ios – 如何使用GraphicContext在Objective C中获得逐渐变细的线条效果所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。