Iphone 要删除标签的边框和固定点吗

Iphone 要删除标签的边框和固定点吗,iphone,ios,Iphone,Ios,我正在创建一个标签,该标签将根据用户的需要通过用户触摸来调整大小,我已经使用github中的类完成了这项工作 但它在标签上显示锚点和边框,我希望在使用“单击背景”时,此锚点和边框将被删除..hlp 编辑 userresizebleview.h文件 @interface UserResizableView : UIView { SPGripViewBorderView *borderView; UIView *contentView; CGPoint touchStart;

我正在创建一个标签,该标签将根据用户的需要通过用户触摸来调整大小,我已经使用github中的类完成了这项工作

但它在标签上显示锚点和边框,我希望在使用“单击背景”时,此锚点和边框将被删除..hlp

编辑

userresizebleview.h文件

@interface UserResizableView : UIView {
    SPGripViewBorderView *borderView;
    UIView *contentView;
    CGPoint touchStart;
    CGFloat minWidth;
    CGFloat minHeight;

    BOOL shouldDrawAnchorPoint;
    // Used to determine which components of the bounds we'll be modifying, based upon where the user's touch started.
    SPUserResizableViewAnchorPoint anchorPoint;

    id <UserResizableViewDelegate> delegate;
}
@interface userresizebleview:UIView{
SPGripViewBorderView*边框视图;
UIView*contentView;
CGPoint触摸启动;
CGF最小宽度;
cg-minHeight;
布尔应拉锚点;
//用于根据用户触摸的起始位置确定要修改边界的哪些组件。
SpuserResilizableeWanchorpoint锚点;
id代表;
}
userresizebleview.m文件

@implementation SPGripViewBorderView

- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
        // Clear background to ensure the content view shows through.
        self.backgroundColor = [UIColor clearColor];
        shouldDrawAnchorPoint = NO;
    }

    return self;
}

- (void)drawRect:(CGRect)rect {
    if(shouldDrawAnchorPoint)
    {
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSaveGState(context);

    // (1) Draw the bounding box.
    CGContextSetLineWidth(context, 1.0);
    CGContextSetStrokeColorWithColor(context, [UIColor clearColor].CGColor);
    CGContextAddRect(context, CGRectInset(self.bounds, kSPUserResizableViewInteractiveBorderSize/2, kSPUserResizableViewInteractiveBorderSize/2));
    CGContextStrokePath(context);

    // (2) Calculate the bounding boxes for each of the anchor points.
    CGRect upperLeft = CGRectMake(0.0, 0.0, kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize);
    CGRect upperRight = CGRectMake(self.bounds.size.width - kSPUserResizableViewInteractiveBorderSize, 0.0, kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize);
    CGRect lowerRight = CGRectMake(self.bounds.size.width - kSPUserResizableViewInteractiveBorderSize, self.bounds.size.height - kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize);
    CGRect lowerLeft = CGRectMake(0.0, self.bounds.size.height - kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize);
    CGRect upperMiddle = CGRectMake((self.bounds.size.width - kSPUserResizableViewInteractiveBorderSize)/2, 0.0, kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize);
    CGRect lowerMiddle = CGRectMake((self.bounds.size.width - kSPUserResizableViewInteractiveBorderSize)/2, self.bounds.size.height - kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize);
    CGRect middleLeft = CGRectMake(0.0, (self.bounds.size.height - kSPUserResizableViewInteractiveBorderSize)/2, kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize);
    CGRect middleRight = CGRectMake(self.bounds.size.width - kSPUserResizableViewInteractiveBorderSize, (self.bounds.size.height - kSPUserResizableViewInteractiveBorderSize)/2, kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize);

    // (3) Create the gradient to paint the anchor points.
    CGFloat colors []= { 
        0.4, 0.8, 1.0, 1.0, 
       0.0, 0.0, 1.0, 1.0
    };
    CGColorSpaceRef baseSpace = CGColorSpaceCreateDeviceRGB();
    CGGradientRef gradient = CGGradientCreateWithColorComponents(baseSpace, NO, NULL, 2);
    CGColorSpaceRelease(baseSpace), baseSpace = NULL;


    // (4) Set up the stroke for drawing the border of each of the anchor points.
    CGContextSetLineWidth(context, 1);
    CGContextSetShadow(context, CGSizeMake(0.5, 0.5), 1);
    CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor);

    // (5) Fill each anchor point using the gradient, then stroke the border.
    CGRect allPoints[8] = { upperLeft, upperRight, lowerRight, lowerLeft, upperMiddle, lowerMiddle, middleLeft, middleRight };
    for (NSInteger i = 0; i < 8; i++) {
        CGRect currPoint = allPoints[i];
        CGContextSaveGState(context);
        CGContextAddEllipseInRect(context, currPoint);
        CGContextClip(context);
        CGPoint startPoint = CGPointMake(CGRectGetMidX(currPoint), CGRectGetMinY(currPoint));
        CGPoint endPoint = CGPointMake(CGRectGetMidX(currPoint), CGRectGetMaxY(currPoint));
        CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
        CGContextRestoreGState(context);
        CGContextStrokeEllipseInRect(context, CGRectInset(currPoint, 1, 1));
    }

    CGGradientRelease(gradient), gradient = NULL;
    CGContextRestoreGState(context);
    }
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    shouldDrawAnchorPoint = YES;
    // Notify the delegate we've begun our editing session.
    if (self.delegate && [self.delegate respondsToSelector:@selector(userResizableViewDidBeginEditing:)]) {
        [self.delegate userResizableViewDidBeginEditing:self];
    }

    [borderView setHidden:NO];
    UITouch *touch = [touches anyObject];
    anchorPoint = [self anchorPointForTouchLocation:[touch locationInView:self]];

    // When resizing, all calculations are done in the superview's coordinate space.
    touchStart = [touch locationInView:self.superview];
    if (![self isResizing]) {
        // When translating, all calculations are done in the view's coordinate space.
        touchStart = [touch locationInView:self];
    }
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    shouldDrawAnchorPoint = NO;
    // Notify the delegate we've ended our editing session.
    if (self.delegate && [self.delegate respondsToSelector:@selector(userResizableViewDidEndEditing:)]) {
        [self.delegate userResizableViewDidEndEditing:self];
        [borderView setHidden:YES];
        UITouch *touch = [touches anyObject];
        anchorPoint = [self anchorPointForTouchLocation:[touch locationInView:self]];
    }
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    shouldDrawAnchorPoint = NO;
    // Notify the delegate we've ended our editing session.
    if (self.delegate && [self.delegate respondsToSelector:@selector(userResizableViewDidEndEditing:)]) {
        [self.delegate userResizableViewDidEndEditing:self];
    }
}
@implementation-spgripvieworderview
-(id)initWithFrame:(CGRect)帧{
if((self=[super initWithFrame:frame])){
//清除背景以确保内容视图显示完整。
self.backgroundColor=[UIColor clearColor];
shouldDrawAnchorPoint=否;
}
回归自我;
}
-(void)drawRect:(CGRect)rect{
if(shouldDrawAnchorPoint)
{
CGContextRef context=UIGraphicsGetCurrentContext();
CGContextSaveGState(上下文);
//(1)绘制边界框。
CGContextSetLineWidth(上下文,1.0);
CGContextSetStrokeColorWithColor(上下文[UIColor clearColor].CGColor);
CGContextAddRect(上下文,CGRectInset(self.bounds,kSPUserResizableViewInteractiveBorderSize/2,kSPUserResizableViewInteractiveBorderSize/2));
CGContextStrokePath(上下文);
//(2)计算每个锚定点的边界框。
CGRect upperLeft=CGRectMake(0.0,0.0,kSPUserResizableViewInteractiveBorderSize,kSPUserResizableViewInteractiveBorderSize);
CGRect upperRight=CGRectMake(self.bounds.size.width-kSPUserResizableViewInteractiveBorderSize,0.0,kSPUserResizableViewInteractiveBorderSize,kSPUserResizableViewInteractiveBorderSize,kSPUserResizableViewInteractiveBorderSize);
CGRect lowerRight=CGRectMake(self.bounds.size.width-kspuserresizebleviewinterActiveBorderSize,self.bounds.size.height-kspuserresizebleviewinterActiveBorderSize,kspuserresizebleviewinterActiveBorderSize,kspuserresizebliewinterActiveBorderSize);
CGRect lowerLeft=CGRectMake(0.0,self.bounds.size.height-kSPUserResizableViewInteractiveBorderSize,kSPUserResizableViewInteractiveBorderSize,kSPUserResizableViewInteractiveBorderSize,kSPUserResizableViewInteractiveBorderSize);
CGRect upperMiddle=CGRectMake((self.bounds.size.width-kspuserResizebleViewInteractiveBorderSize)/2,0.0,kspuserResizebleViewInteractiveBorderSize,kspuserResizebleViewInteractiveBorderSize);
CGRect LOWERMIDLE=CGRectMake((self.bounds.size.width-kspuserresizeblevievieinteractivebordersize)/2,self.bounds.size.height-kspuserresizebleviewiinteractivebordersize,kspuserresizebleviewiinteractivebordersize,kspuserresizebleviewiinteractivebordersize);
CGRect MIDLEFT=CGRectMake(0.0,(self.bounds.size.height-kspuserresizablevievieinteractivebordersize)/2,kspuserresizableviewiinteractivebordersize,kspuserresizableviewiinteractivebordersize);
CGRect middleRight=CGRectMake(self.bounds.size.width-kspuserresizeblevievieinteractiveborderSize,(self.bounds.size.height-kspuserresizebleviewiinteractiveborderSize)/2,kspuserresizebleviewiinteractiveborderSize,kspuserresizebleviewiinteractiveborderSize);
//(3)创建渐变以绘制锚点。
CGFloat颜色[]={
0.4, 0.8, 1.0, 1.0, 
0.0, 0.0, 1.0, 1.0
};
CGColorSpaceRef baseSpace=CGColorSpaceCreateDeviceRGB();
CGGradientRef gradient=CGGradientCreateWithColorComponents(baseSpace,NO,NULL,2);
CGColorSpaceRelease(baseSpace),baseSpace=NULL;
//(4)设置绘制每个锚定点边界的行程。
CGContextSetLineWidth(上下文,1);
CGContextSetShadow(上下文,CGSizeMake(0.5,0.5),1);
CGContextSetStrokeColorWithColor(上下文[UIColor blackColor].CGColor);
//(5)使用坡度填充每个锚定点,然后划过边界。
CGRect allPoints[8]={upperLeft,upperRight,lowerRight,lowerLeft,upperMiddle,lowerMiddle,middleLeft,middleRight};
对于(NSInteger i=0;i<8;i++){
CGRect currPoint=所有点[i];
CGContextSaveGState(上下文);
CGContextAddEllipseInRect(上下文,currPoint);
CGContextClip(上下文);
CGPoint startPoint=CGPointMake(CGRectGetMidX(currPoint),CGRectGetMinY(currPoint));
CGPoint endPoint=CGPointMake(CGRectGetMidX(currPoint),CGRectGetMaxY(currPoint));
CGContextDrawLinearGradient(上下文、渐变、起点、终点,0);
CGContextRestoreGState(上下文);
CGContextStrokeEllipseInRect(上下文,CGRectInset(currPoint,1,1));
}
CGGradientRelease(梯度),梯度=NULL;
CGContextRestoreGState(上下文);
}
}
-(无效)触摸开始:(NSSet*)触摸事件:(UIEvent*)事件{
shouldDrawAnchorPoint=是;
//通知学员我们已开始编辑课程。
if(self.delegate&&[self.delegate respondsToSelector:@selector(userresizeableviewidbeginediting:))){
[self.delegate userresizeableviewdibeginediting:self];
}
[边界视图设置隐藏:否];
UITouch*touch=[触摸任何对象];
anchorPoint=[self anchorPointForTouchLocation:[touch locationInView:self]];
//调整大小时,所有计算都在superview的坐标空间中完成。
touchStart=[TouchLocationInView:self.superview];
如果(![self isresising]){
//平移时,所有计算都在视图的坐标空间中完成。
touchStart=[触摸位置查看:自];
}
}
-(void)touchesend:(NSSet*)toucheevent:(UIEvent*)event{
shouldDrawAnchorPoint=否;
//通知学员我们已结束编辑会话。
if(self.delegate&[self.delegate respondsToSelector:@selector(userresizeableviewdidendediting:))){
[self.del]
@interface SPGripViewBorderView : UIView
{
  BOOL shouldDrawAnchorPoint;
}

@property(nonatomic, readwrite) BOOL shouldDrawAnchorPoint;

@end
@implementation SPGripViewBorderView

@synthesize shouldDrawAnchorPoint;

- (id)initWithFrame:(CGRect)frame {
    if ((self = [super initWithFrame:frame])) {
        // Clear background to ensure the content view shows through.
        self.backgroundColor = [UIColor clearColor];
        shouldDrawAnchorPoint = NO;
    }
    return self;
}

- (void)drawRect:(CGRect)rect {

    if(shouldDrawAnchorPoint)
    {
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSaveGState(context);

        // (1) Draw the bounding box.
        CGContextSetLineWidth(context, 1.0);
        CGContextSetStrokeColorWithColor(context, [UIColor blueColor].CGColor);
        CGContextAddRect(context, CGRectInset(self.bounds, kSPUserResizableViewInteractiveBorderSize/2, kSPUserResizableViewInteractiveBorderSize/2));
        CGContextStrokePath(context);

        // (2) Calculate the bounding boxes for each of the anchor points.
        CGRect upperLeft = CGRectMake(0.0, 0.0, kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize);
        CGRect upperRight = CGRectMake(self.bounds.size.width - kSPUserResizableViewInteractiveBorderSize, 0.0, kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize);
        CGRect lowerRight = CGRectMake(self.bounds.size.width - kSPUserResizableViewInteractiveBorderSize, self.bounds.size.height - kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize);
        CGRect lowerLeft = CGRectMake(0.0, self.bounds.size.height - kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize);
        CGRect upperMiddle = CGRectMake((self.bounds.size.width - kSPUserResizableViewInteractiveBorderSize)/2, 0.0, kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize);
        CGRect lowerMiddle = CGRectMake((self.bounds.size.width - kSPUserResizableViewInteractiveBorderSize)/2, self.bounds.size.height - kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize);
        CGRect middleLeft = CGRectMake(0.0, (self.bounds.size.height - kSPUserResizableViewInteractiveBorderSize)/2, kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize);
        CGRect middleRight = CGRectMake(self.bounds.size.width - kSPUserResizableViewInteractiveBorderSize, (self.bounds.size.height - kSPUserResizableViewInteractiveBorderSize)/2, kSPUserResizableViewInteractiveBorderSize, kSPUserResizableViewInteractiveBorderSize);

        // (3) Create the gradient to paint the anchor points.
        CGFloat colors [] = {
        0.4, 0.8, 1.0, 1.0,
        0.0, 0.0, 1.0, 1.0
        };
        CGColorSpaceRef baseSpace = CGColorSpaceCreateDeviceRGB();
        CGGradientRef gradient = CGGradientCreateWithColorComponents(baseSpace, colors, NULL, 2);
        CGColorSpaceRelease(baseSpace), baseSpace = NULL;

        // (4) Set up the stroke for drawing the border of each of the anchor points.
        CGContextSetLineWidth(context, 1);
        CGContextSetShadow(context, CGSizeMake(0.5, 0.5), 1);
        CGContextSetStrokeColorWithColor(context, [UIColor whiteColor].CGColor);

        // (5) Fill each anchor point using the gradient, then stroke the border.
        CGRect allPoints[8] = { upperLeft, upperRight, lowerRight, lowerLeft, upperMiddle, lowerMiddle, middleLeft, middleRight };
        for (NSInteger i = 0; i < 8; i++) {
            CGRect currPoint = allPoints[i];
            CGContextSaveGState(context);
            CGContextAddEllipseInRect(context, currPoint);
            CGContextClip(context);
            CGPoint startPoint = CGPointMake(CGRectGetMidX(currPoint), CGRectGetMinY(currPoint));
            CGPoint endPoint = CGPointMake(CGRectGetMidX(currPoint), CGRectGetMaxY(currPoint));
            CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
            CGContextRestoreGState(context);
            CGContextStrokeEllipseInRect(context, CGRectInset(currPoint, 1, 1));
        }
        CGGradientRelease(gradient), gradient = NULL;
        CGContextRestoreGState(context);
    }
}
@end
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    borderView.shouldDrawAnchorPoint = YES;
    [borderView needsDisplay];

    // Notify the delegate we've begun our editing session.
    if (self.delegate && [self.delegate respondsToSelector:@selector(userResizableViewDidBeginEditing:)]) {
        [self.delegate userResizableViewDidBeginEditing:self];
    }

    [borderView setHidden:NO];
    UITouch *touch = [touches anyObject];
    anchorPoint = [self anchorPointForTouchLocation:[touch locationInView:self]];

    // When resizing, all calculations are done in the superview's coordinate space.
    touchStart = [touch locationInView:self.superview];
    if (![self isResizing]) {
        // When translating, all calculations are done in the view's coordinate space.
        touchStart = [touch locationInView:self];
    }
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    borderView.shouldDrawAnchorPoint = NO;
    [borderView needsDisplay];

    // Notify the delegate we've ended our editing session.
    if (self.delegate && [self.delegate respondsToSelector:@selector(userResizableViewDidEndEditing:)]) {
        [self.delegate userResizableViewDidEndEditing:self];
    }
}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    borderView.shouldDrawAnchorPoint = NO;
    [borderView needsDisplay];

    // Notify the delegate we've ended our editing session.
    if (self.delegate && [self.delegate respondsToSelector:@selector(userResizableViewDidEndEditing:)]) {
        [self.delegate userResizableViewDidEndEditing:self];
    }
}