在iphone中的全屏模式下画线触摸事件不能完美工作

我创build应用程序来绘制iPhone成功。但是,它只是工作设置状态栏是最初隐藏=否在myapp-info.plist.else如果,设置状态栏是最初隐藏=是不工作Perfectly.My viewcontroller代码在下面:

- (void)viewDidLoad { [super viewDidLoad]; drawImage = [[UIImageView alloc] initWithImage:nil]; drawImage.frame = self.view.frame; drawImage.backgroundColor=[UIColor blackColor]; [self.view addSubview:drawImage]; mouseMoved = 0; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { mouseSwiped = NO; UITouch *touch = [touches anyObject]; if ([touch tapCount] == 2) { drawImage.image = nil; return; } lastPoint = [touch locationInView:self.view]; //lastPoint.y -= 20; } -(void)viewDidAppear:(BOOL)animated { // [UIApplication sharedApplication].statusBarHidden = NO; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { mouseSwiped = YES; UITouch *touch = [touches anyObject]; CGPoint currentPoint = [touch locationInView:self.view]; currentPoint.y -= 20; // only for 'kCGLineCapRound' UIGraphicsBeginImageContext(self.view.frame.size); //Albert Renshaw - Apps4Life [drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)]; //originally self.frame.size.width, self.frame.size.height)]; CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); //kCGLineCapSquare, kCGLineCapButt, kCGLineCapRound CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0); // for size CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 1.0, 0.0, 1.0); //values for R, G, B, and Alpha 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) { drawImage.image = nil; return; } if(!mouseSwiped) { //if color == green UIGraphicsBeginImageContext(self.view.frame.size); [drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)]; //originally self.frame.size.width, self.frame.size.height)]; CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); //kCGLineCapSquare, kCGLineCapButt, kCGLineCapRound CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10.0); CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 1.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(); } } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)viewDidUnload { [self setDrawImage:nil]; [self setMy_view:nil]; // Release any retained subviews of the main view. // eg self.myOutlet = nil; } - (void)dealloc { [my_view release]; [drawImage release]; [super dealloc]; } 

此代码完美工作,没有全屏模式。else,不工作像下面的输出:

在这里输入图像说明

请任何人帮助我们任何代码或例子…!

谢谢..!

移动drawImage.frame = self.view.frame;
- (void)viewDidLoad方法

-(void)viewWillAppear:(BOOL)animated
应该在viewWillAppear或viewDidAppear中进行任何几何调整。

终于我得到它的解决scheme我的控制器类下面:

 - (void)viewDidLoad { [super viewDidLoad]; } -(void)viewWillAppear:(BOOL)animated { drawImage = [[UIImageView alloc] initWithImage:nil]; drawImage.frame = self.view.frame; drawImage.backgroundColor=[UIColor blackColor]; drawImage.center=self.view.center; [self.view addSubview:drawImage]; mouseMoved = 0; } - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { mouseSwiped = NO; UITouch *touch = [touches anyObject]; if ([touch tapCount] == 2) { drawImage.image = nil; return; } lastPoint = [touch locationInView:self.view]; lastPoint.y -= 0; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { mouseSwiped = YES; UITouch *touch = [touches anyObject]; CGPoint currentPoint = [touch locationInView:self.view]; //currentPoint.y += 20; // only for 'kCGLineCapRound' UIGraphicsBeginImageContext(self.view.frame.size); //Albert Renshaw - Apps4Life [drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)]; //originally self.frame.size.width, self.frame.size.height)]; CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); //kCGLineCapSquare, kCGLineCapButt, kCGLineCapRound CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0); // for size CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 1.0, 0.0, 1.0); //values for R, G, B, and Alpha 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) { drawImage.image = nil; return; } if(!mouseSwiped) { //if color == green UIGraphicsBeginImageContext(self.view.frame.size); [drawImage.image drawInRect:CGRectMake(0, 0, drawImage.frame.size.width, drawImage.frame.size.height)]; //originally self.frame.size.width, self.frame.size.height)]; CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound); //kCGLineCapSquare, kCGLineCapButt, kCGLineCapRound CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10.0); CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 0.0, 1.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(); } } - (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)viewDidUnload { [self setDrawImage:nil]; [self setMy_view:nil]; // Release any retained subviews of the main view. // eg self.myOutlet = nil; } - (void)dealloc { [my_view release]; [drawImage release]; [super dealloc]; }