我試圖汲取其中用戶移動手指在iPad上的矩形:在iOS上,爲什麼在下面的代碼中沒有繪圖?
視圖控制器的接口:
@interface ViewController : UIViewController {
NSMutableArray *paths;
}
實現:
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *touch in touches) {
CGPoint location = [touch locationInView:self.view];
CGRect aRectangle = CGRectMake(location.x, location.y, 40, 40);
UIBezierPath *path = [UIBezierPath bezierPathWithRect:aRectangle];
path = [UIBezierPath bezierPathWithOvalInRect:aRectangle];
[paths addObject:path];
}
}
- (void)drawRect:(CGRect)rect {
for (UIBezierPath *path in paths) {
[path fill];
}
}
但絕對不會在屏幕上繪製。 ..我想也許我沒有告訴視圖刷新自己,並呼籲drawRect
,但我試圖去iPad的主屏幕,並重新進入應用程序,仍然沒有表現出來?
(我打算使用點數組,但由於CGPoint
不是一個將保留的對象,所以它不能被添加到可變數組中,並且在本地作用域結束後它將消失。它可以是一組點嗎?)
請嘗試以下帖子以供繪製......! http://stackoverflow.com/questions/10226130/draw-lines-a-touches-event-not-work-perfectly-on-fullscreen-mode-in-iphone 謝謝..! – Dinesh 2012-04-21 04:53:49