2011-03-08 62 views
0

我在底部添加了一個工具欄,它在繪圖時消失,但我無法繪製到屏幕的底部。我嘗試了邊界或框架,但都沒有工作。我只有一個觀點,順便說一句。太多的底部周圍畫會引起周圍iPhone繪圖到屏幕問題

Picture of Problem

- (void)viewDidLoad { 

    [super viewDidLoad]; 
    drawImage = [[UIImageView alloc] initWithImage:nil]; 
    drawImage.frame = self.view.frame; 
    [self.view addSubview:drawImage]; 
    self.view.backgroundColor = [UIColor lightGrayColor]; 
    mouseMoved = 0; 
} 

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 

    toolbar.hidden = YES; 

    mouseSwiped = NO; 
    UITouch *touch = [touches anyObject]; 

    if ([touch tapCount] == 2) { 
     drawImage.image = nil; 
     return; 
    } 

    lastPoint = [touch locationInView:self.view]; 
    lastPoint.y -= 20; 

} 


- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    mouseSwiped = YES; 

    UITouch *touch = [touches anyObject]; 
    CGPoint currentPoint = [touch locationInView:self.view]; 
    currentPoint.y -= 20; 


    UIGraphicsBeginImageContext(self.view.frame 
           .size); 
    [drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); 
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0); 
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0); 
    CGContextBeginPath(UIGraphicsGetCurrentContext()); 
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y); 
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y); 
    CGContextStrokePath(UIGraphicsGetCurrentContext()); 
    drawImage.image = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    lastPoint = currentPoint; 

    mouseMoved++; 

    if (mouseMoved == 10) { 
     mouseMoved = 0; 
    } 

} 

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 

    UITouch *touch = [touches anyObject]; 

    if ([touch tapCount] == 2) { 
     toolbar.hidden = NO; 
     drawImage.image = nil; 
     return; 
    } 


    if(!mouseSwiped) { 
     UIGraphicsBeginImageContext(self.view.frame.size); 
     [drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
     CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); 
     CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0); 
     CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0); 
     CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y); 
     CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y); 
     CGContextStrokePath(UIGraphicsGetCurrentContext()); 
     CGContextFlush(UIGraphicsGetCurrentContext()); 
     drawImage.image = UIGraphicsGetImageFromCurrentImageContext(); 
     UIGraphicsEndImageContext(); 
    } 
} 
+0

你有沒有特異性y幀的大小? – 2011-06-05 18:23:19

回答

1

全貌請設置

lastPoint.y -= 0; 

currentPoint.y -= 0; 

這對我的作品