0

以下是我在 UITextView 上绘制角的代码。

在 .h 文件中:

    @property(nonatomic,strong)  UIBezierPath *   upperLeft;
    @property(nonatomic,strong)  UIBezierPath *   upperRight;

-  (void)drawRect:(CGRect)rect
{

 upperLeft = [UIBezierPath bezierPathWithArcCenter:CGPointMake(xCorner + margin, yCorner + margin)
                                                   radius:5.5
                                               startAngle:0
                                                 endAngle:DEGREES_TO_RADIANS(360)
                                                clockwise:YES];
        [[UIColor blackColor]setFill];
        [upperLeft fill];
        [upperLeft closePath];

upperRight = [UIBezierPath bezierPathWithArcCenter:CGPointMake(xCorner+ widths - margin, yCorner + margin)
                                                radius:5.5
                                            startAngle:0
                                              endAngle:DEGREES_TO_RADIANS(360)
                                             clockwise:YES];
    [[UIColor blackColor]setFill];
    [upperRight fill];
    [upperRight closePath];
}

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

     touchStart  =  [[touches anyObject] locationInView:self];

    isResizingUL = [upperLeft containsPoint:touchStart];
    isResizingUR= [upperRight containsPoint:touchStart];
}

当我第一次点击路径时,它会给出布尔值是。但是对于以后的命中,它会为任何路径赋予 NO 值。即使命中路径。任何人都可以帮助我为什么会这样。

4

1 回答 1

0

看起来您正在尝试存储 upperLeft 和 lowerRight,但您没有使用该属性,因此 ARC 不会通过保留这些值来帮助您。因此,当您超出范围时,upperLeft 和 lowerRight 将变得未定义。我有点惊讶它没有崩溃。

如果你使用self.upperLeft=...and self.lowerRight=...,你应该会成功。

于 2012-06-08T11:36:56.120 回答