- (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中获得逐渐变细的线条效果所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)