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];
}

初めてパスをタップすると、ブール値がyesになります。しかし、その後のヒットでは、どのパスにも値 NO が与えられます。パスでヒットしたとしても。なぜそれが起こっているのか、誰でも私を助けることができますか?

4

1 に答える 1

0

upperLeft と lowerRight を格納しようとしているように見えますが、プロパティを使用していないため、ARC は値を保持することで役に立ちません。したがって、範囲外になると、upperLeft と lowerRight が未定義になります。壊れていないことに少し驚いています。

と を使用するself.upperLeft=...self.lowerRight=...、成功するはずです。

于 2012-06-08T11:36:56.120 に答える