2013-07-25 35 views
0

我想做的事情在ios.I繪製過的UIImageView我能夠在整個屏幕上繪製圖紙,但我想提請在特定區域only.My代碼繪製的是: -繪製在iOS應用程序

UITouch *touch = [touches anyObject];  
    currentPoint = [touch locationInView:self.view]; //// tracing whatever ur finger touching the screen 
    NSLog(@"%data",currentPoint); 
    UIGraphicsBeginImageContext(CGSizeMake (300,568)) ; /// (300,568)); //// 320, 568, 480 iph4 screen ,568 ip5 screen 
    [drawImage.image drawInRect:CGRectMake(0,0, 300,568)]; //(0,0, 300,568)]; 
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); // round line 
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 18.0); //// LINE WIDTH DIAMETER THE STROKE 
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1, 1, 1, 1); ///// RGB COLOUR 
    CGContextBeginPath(UIGraphicsGetCurrentContext()); ///// START WHEN WE DRAW THE PATH. 
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y); ///// 
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y); 
    CGContextStrokePath(UIGraphicsGetCurrentContext()); 

    // CGContextStrokePath(UIGraphicsGetCurrentContext()) ; 
    [drawImage setFrame:CGRectMake (0,0, 300, 568)]; //// (0, 0, 300,568)]; ///(100, 100, 150,280)]; 
    drawImage.image = UIGraphicsGetImageFromCurrentImageContext(); ///// WHOLE UPPER PARA defined 
UIGraphicsEndImageContext(); //// DONE DRAWING 
lastPoint = currentPoint; //// 
+0

哪個特定區域? – Raptor

+0

...你想要幫助嗎? – trojanfoe

+0

我想只繪製放置在屏幕中心的UI圖像,其大小爲CGRectMake(40,80,250,290)]; –

回答

0

創建的UIView的子類,覆蓋drawRect

- (void)drawRect:(CGRect)rect 
{ 
    // do your drawing here 
} 

作爲一個子視圖添加您以您的UIImageView

MyCustomView *customView = [[MyCustomView alloc] initWithFrame:self.imageView.bounds]; 
[self.imageView addSubview:customView]; 

用您想要自定義繪圖的參數更新您的視圖。