2011-06-06 56 views
0

我有我可以繪製的視圖。當用戶點擊取消按鈕時,視圖被清除並且在該視圖中繪製新的圖像。我張貼我的代碼。誰能幫忙?如何刪除視圖並重繪它

#import "SignatureViewController.h" 


@implementation SignatureViewController 
@synthesize salesToolBar; 



-(void)buttonpressed 
{ 
    NSString *allElements = [myarray componentsJoinedByString:@""]; 
    NSLog(@"%@", allElements);} 


-(void)buttonclear{ 

     [drawImage removeFromSuperview]; 

    //UIGraphicsBeginImageContext(CGSizeMake(self.view.frame.size.height, self.view.frame.size.width));  
    drawImage = [[UIImageView alloc] initWithImage:nil]; 
    [drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.height, self.view.frame.size.width)]; 
    drawImage.frame = self.view.frame; 
    [self.view addSubview:drawImage]; 
    self.view.backgroundColor = [UIColor greenColor]; 
    mouseMoved = 0; 
     //[super viewDidLoad]; 

} 

-(void)buttoncancel{ 
    [[self navigationController] popViewControllerAnimated: YES]; 
    [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait; 

} 


- (void)viewDidLoad { 
    [super viewDidLoad]; 
    myarray = [[NSMutableArray alloc] init]; 


    CGFloat x = self.view.bounds.size.width/2.0; 
    CGFloat y = self.view.bounds.size.height/2.0; 
    CGPoint center = CGPointMake(y, x); 

    // set the new center point 
    self.view.center = center; 

    CGAffineTransform transform = self.view.transform; 
     transform = CGAffineTransformRotate(transform, -(M_PI/2.0)); 

    self.view.transform = transform; 

    self.view.backgroundColor = [UIColor greenColor]; 
    self.title = @"Signature"; 

    [self createToolbar]; 

    NSLog(@"View Did Load Run"); 


} 

- (void)viewDidAppear:(BOOL)animated { 
    NSLog(@"Self.view.frame.height = %f and width = %f ", self.view.frame.size.height, self.view.frame.size.width); 
    NSLog(@"View Did Appear Run"); 
    self.navigationController.navigationBarHidden=TRUE; 
    [UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft; 



    [super viewDidLoad]; 

} 
+0

幫助什麼? – Abizern 2011-06-06 18:49:33

+0

你能更精確地滿足你的需求嗎?這個新圖像如何可用?現在它似乎沒有。您正在向它發送一個'drawInRect:'消息。此代碼還有一些錯誤。 – 2011-06-06 18:50:29

回答

0

聽起來像你需要調用setNeedsDisplay:在視圖上。 :)

+0

那麼圖像是一個視圖上繪製的圖像。我的imageview被稱爲drawimage.I發佈整個code.I認爲我修復了除取消按鈕之外的所有。 – user771385 2011-06-06 18:53:55

+0

是的,所以請嘗試在包含imageview的視圖上調用以下... [self.view setNeedsDisplay]; – Luke 2011-06-06 18:56:51

+0

我的視圖沒有正確清除,所以在按鈕清除後,當我嘗試重新繪製圖像時,我只獲得屏幕的一部分,整個屏幕在第一次可用。因此,我需要幫助調整屏幕大小以使After按鈕清除我獲得全屏。 – user771385 2011-06-06 19:00:18

相關問題