You can do this by tracking the minimum and maximum touch values.
For example, do min / max ivars
@interface ViewController () { CGFloat touchRectMinX_; CGFloat touchRectMinY_; CGFloat touchRectMaxX_; CGFloat touchRectMaxY_; UIView *demoView_; } @end
Here is the daemon release
- (void)viewDidLoad { [super viewDidLoad]; demoView_ = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)]; demoView_.backgroundColor = [UIColor redColor]; [self.view addSubview:demoView_]; }
Set them with impossible values. You want to do this for every signature, not every hit, but how you do it is up to you. I suggest reset on 'clear' if you have a clear button.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { touchRectMinX_ = CGFLOAT_MAX; touchRectMinY_ = CGFLOAT_MAX; touchRectMaxX_ = CGFLOAT_MIN; touchRectMaxY_ = CGFLOAT_MIN; }
Now record the changes
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint currentPoint = [touch locationInView:self.view]; touchRectMinX_ = MIN(touchRectMinX_, currentPoint.x); touchRectMinY_ = MIN(touchRectMinY_, currentPoint.y); touchRectMaxX_ = MAX(touchRectMaxX_, currentPoint.x); touchRectMaxY_ = MAX(touchRectMaxY_, currentPoint.y);
Hope this helps!
Matt melton
source share