iphone – 是否有SDK在iOS上通过触摸绘制线条?

iphone – 是否有SDK在iOS上通过触摸绘制线条?,第1张

概述是否有一个框架,我可以使用触摸绘制线条.基本上我想为客户添加登录iPad / iPhone并将其作为图像捕获的能力. 任何帮助非常感谢. 谢谢. 您可以使用UIKIT框架中提供的核心图形来满足您的要求. 我在我的应用程序中有类似的要求,有不同的用途,如果需要,我可以为您提供代码. TNQ .h文件 #import <UIKit/UIKit.h>typedef enum _DrawingMode{ 是否有一个框架,我可以使用触摸绘制线条.基本上我想为客户添加登录iPad / iPhone并将其作为图像捕获的能力.

任何帮助非常感谢.

谢谢.

解决方法 您可以使用UIKIT框架中提供的核心图形来满足您的要求.

我在我的应用程序中有类似的要求,有不同的用途,如果需要,我可以为您提供代码.

TNQ

.h文件

#import <UIKit/UIKit.h>typedef enum _DrawingMode{DrawingModePen =0,DrawingModeEraser=1,} DrawingMode;@interface DrawingVIEw : UIVIEw {CGPoint lastPoint;UIImageVIEw *drawImage;BOol mouseSwiped;   int mouseMoved;DrawingMode mode;UIcolor *_drawingPencolor;}@property (nonatomic,retain) UIcolor *drawingPencolor;@property (nonatomic) DrawingMode mode;@property (nonatomic,retain) UIImageVIEw *imageVIEw;@property (nonatomic,retain)UIImageVIEw *drawImage;@end

.M

#import "DrawingVIEw.h"@implementation DrawingVIEw@synthesize mode,drawingPencolor=_drawingPencolor,imageVIEw=drawImage;-(voID)initialize{    drawImage = [[UIImageVIEw alloc] initWithImage:nil];    self.autoresizesSubvIEws = YES;    drawImage.autoresizingMask = (UIVIEwautoresizingFlexibleWIDth | UIVIEwautoresizingFlexibleHeight);    drawImage.frame = self.bounds;    [self addSubvIEw:drawImage];    self.backgroundcolor = [UIcolor clearcolor];    mouseMoved = 0;    _drawingPencolor = [[UIcolor alloc] initWithWhite:0.0 Alpha:1.0];}-(voID)maskImage:(UIImage *)image withMask:(UIImage *)maskImage {    CGImageRef maskRef = maskImage.CGImage;     CGImageRef mask = CGImageMaskCreate(CGImageGetWIDth(maskRef),CGImageGetHeight(maskRef),CGImageGetBitsPerComponent(maskRef),CGImageGetBitsPerPixel(maskRef),CGImageGetBytesPerRow(maskRef),CGImageGetDataProvIDer(maskRef),NulL,false);    CGImageRef masked = CGImageCreateWithMask([image CGImage],mask);    UIImage *tempImage = [[UIImage alloc] initWithCGImage:masked];    //self.clippedImage = tempImage;    [tempImage release];    CFRelease(masked);    CFRelease(mask);}-(voID)awakeFromNib{    [self initialize];}- (ID)initWithFrame:(CGRect)frame {    if ((self = [super initWithFrame:frame])) {        // Initialization code        [self initialize];    }    return self;}- (voID)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {    mouseSwiped = NO;    UItouch *touch = [touches anyObject];    if ([touch tapCount] == 2) {        drawImage.image = nil;        return;    }    lastPoint = [touch locationInVIEw:self];    //lastPoint.y -= 20;    NSLog(@"touches begin");}- (voID)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {    mouseSwiped = YES;    UItouch *touch = [touches anyObject];       CGPoint currentPoint = [touch locationInVIEw:self];    //currentPoint.y -= 20;    UIGraphicsBeginImageContext(self.bounds.size);    [drawImage.image drawInRect:CGRectMake(0,self.bounds.size.wIDth,self.bounds.size.height)];    CGContextSetlineCap(UIGraphicsGetCurrentContext(),kCGlineCapRound);    CGContextSetlinewidth(UIGraphicsGetCurrentContext(),5.0);    if (mode == DrawingModePen) {        NSLog(@"drawing");        CGContextSetstrokecolorWithcolor(UIGraphicsGetCurrentContext(),[_drawingPencolor CGcolor]);    }    else {        CGContextSetstrokecolorWithcolor(UIGraphicsGetCurrentContext(),[[UIcolor clearcolor] CGcolor]);        CGContextBeginPath(UIGraphicsGetCurrentContext());        CGContextMovetoPoint(UIGraphicsGetCurrentContext(),lastPoint.x,lastPoint.y);        CGContextClearRect (UIGraphicsGetCurrentContext(),CGRectMake(lastPoint.x,lastPoint.y,20,20));        CGContextstrokePath(UIGraphicsGetCurrentContext());        NSLog(@"clearing");            }    CGContextBeginPath(UIGraphicsGetCurrentContext());    CGContextMovetoPoint(UIGraphicsGetCurrentContext(),lastPoint.y);    CGContextAddlinetoPoint(UIGraphicsGetCurrentContext(),currentPoint.x,currentPoint.y);    CGContextstrokePath(UIGraphicsGetCurrentContext());    drawImage.image = UIGraphicsGetimageFromCurrentimageContext();    UIGraphicsEndImageContext();    lastPoint = currentPoint;    mouseMoved++;    if (mouseMoved == 10) {        mouseMoved = 0;    }}- (voID)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {    UItouch *touch = [touches anyObject];    if ([touch tapCount] == 2) {        drawImage.image = nil;        return;    }    if(!mouseSwiped) {        UIGraphicsBeginImageContext(self.bounds.size);        [drawImage.image drawInRect:CGRectMake(0,self.bounds.size.height)];        CGContextSetlineCap(UIGraphicsGetCurrentContext(),kCGlineCapRound);        CGContextSetlinewidth(UIGraphicsGetCurrentContext(),5.0);        CGContextMovetoPoint(UIGraphicsGetCurrentContext(),lastPoint.y);        CGContextAddlinetoPoint(UIGraphicsGetCurrentContext(),lastPoint.y);        if (mode == DrawingModePen) {            CGContextSetstrokecolorWithcolor(UIGraphicsGetCurrentContext(),[_drawingPencolor CGcolor]);        }        else {            CGContextSetstrokecolorWithcolor(UIGraphicsGetCurrentContext(),[self.backgroundcolor CGcolor]);        }        CGContextstrokePath(UIGraphicsGetCurrentContext());        CGContextFlush(UIGraphicsGetCurrentContext());        drawImage.image = UIGraphicsGetimageFromCurrentimageContext();        UIGraphicsEndImageContext();    }}- (voID)dealloc {    [drawImage release];    [_drawingPencolor release];    [super dealloc];}@end
总结

以上是内存溢出为你收集整理的iphone – 是否有SDK在iOS上通过触摸绘制线条?全部内容,希望文章能够帮你解决iphone – 是否有SDK在iOS上通过触摸绘制线条?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1083275.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存