0

以下のコードは ARC では正常に動作しますが、非 arc では動作しません。実際には、このフリーハンド描画を非アーク コードで実装したいと考えています。非円弧の問題は、ポインタがある場所にあり、線が別の場所に描画されていることです。
参照用のスクリーン ショットを次に示します。

コード: in .h

UIImageView *drawImage;
CGPoint location;
CGPoint lastPoint;
CGPoint moveBackTo;
CGPoint currentPoint;
NSDate *lastClick;
BOOL mouseSwiped;
NSMutableArray *latLang;
  ///
- (void)viewDidLoad
{
[super viewDidLoad];

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
drawImage.image = [defaults objectForKey:@"drawImageKey"];
drawImage = [[UIImageView alloc] initWithImage:nil];
drawImage.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[self.view addSubview:drawImage];
drawImage.backgroundColor = [UIColor blueColor];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];

if ([touch tapCount] == 2) {
    drawImage.image = nil;
}


location = [touch locationInView:self.view];
lastClick = [NSDate date];

lastPoint = [touch locationInView:self.view];
NSLog(@"LastPoint:%@",NSStringFromCGPoint(lastPoint));
lastPoint.y -= 0;
mouseSwiped = YES;
[super touchesBegan: touches withEvent: event];


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

UITouch *touch = [touches anyObject];
currentPoint = [touch locationInView:self.view];
UIGraphicsBeginImageContext(CGSizeMake(self.view.frame.size.width, self.view.frame.size.height));
[drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 8.0);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0, 1, 0, 1);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());


[drawImage setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
if (mouseSwiped) {

}
lastPoint = currentPoint;

[self.view addSubview:drawImage];
}
4

1 に答える 1

0

問題は、lastClick の自動リリースにあると思います。最も簡単なことは置き換えることができます:

NSDate *lastClick;

@property (strong, nonatomic) NSDate *lastClick;

...わかりました、ARCとARCなしを混同しました。ARCがないことに問題があるため、日付を保持する必要があります:

lastClick = [[NSDate date] retain];

次に、実装で touchesEnd のハンドラーを追加します。

[lastClick release];
lastClick = nil;
于 2013-09-23T14:32:11.890 に答える