First, declare several properties
@property (Nonatomic,strong) uibezierpath ** shapelayer;
Then register the drag events on the screen and initialize the Bezier curves and Cashapelayer
- (void) viewdidload {[Super viewdidload]; Uipangesturerecognizer* Pan =[[Uipangesturerecognizer alloc]initwithtarget:self Action: @selector (Pantouch:)]; [Self.view Addgesturerecognizer:pan]; Self.beizer=[Uibezierpath Bezierpath]; [Self initcashaper];}-(void) initcashaper{Self.shapelayer= [CashapelayerNew]; Self.shapelayer.frame= CGRectMake (0,0, Self.view.frame.size.width, self.view.frame.size.height); Self.shapelayer.fillColor=Nil; Self.shapelayer.lineCap=Kcalinecapround; Self.shapelayer.strokeColor=[Uicolor Cyancolor]. Cgcolor; Self.shapelayer.lineWidth=2; [Self.view.layer AddSublayer:self.shapelayer];}
Immediately following the handling of drag events
-(void) Pantouch: (Uipangesturerecognizer *) pan{ = [pan LocationInView:self.view]; if (Pan.state = = Uigesturerecognizerstatebegan) { [Self.beizer movetopoint:_startpoint]; } if (Pan.state = = uigesturerecognizerstatechanged) { = [pan LocationInView:self.view]; [_beizer Addlinetopoint:_movepoint]; = _beizer. Cgpath;} }
Done.
IOS---Simple effects for real-time drawing on the screen---cashaperlayer and uibezierpath easy to use