Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to draw graphics in iphone gesture?
    text
    copied!<p>I have a question to draw a line or circle indicator after user has pan gesture (i.e. user touches and drags their finger) on iPhone. However, UIGraphicsGetCurrentContext() always returns nil, does anyone know how to implement this on iPhone? </p> <p>Thanks, clu</p> <pre><code>@interface MyView : UIView &lt;UIGestureRecognizerDelegate&gt; { CGPoint location; PanIndicator *panIndicator; } @implementation MyView - (id)init { if (self = [super init]) { UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)]; [panGesture setMaximumNumberOfTouches:1]; [panGesture setDelegate:self]; [self addGestureRecognizer:panGesture]; [panGesture release]; panIndicator = [[PanIndicator alloc] init]; [self addSubview:panIndicator]; } return self; } - (void)panAction:(UIPanGestureRecognizer *)gR { if ([gR state]==UIGestureRecognizerStateBegan) { location = [gR locationInView:self]; } else if ([gR state]==UIGestureRecognizerStateEnded) { // The following code in this block is useless due to context = nil // CGContextRef context = UIGraphicsGetCurrentContext(); // CGContextAddRect(context, CGRectMake(30.0, 30.0, 60.0, 60.0)); // CGContextStrokePath(context); } else if ([gR state]==UIGestureRecognizerStateChanged) { CGPoint location2 = [gR locationInView:self]; panIndicator.frame = self.bounds; panIndicator.startPoint = location; panIndicator.endPoint = location2; // [panIndicator setNeedsDisplay]; //I don't know why PanIncicator:drawRect doesn't get called [panIndicator drawRect:CGRectMake(0, 0, 100, 100)]; //CGRectMake is useless } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload