画线触摸事件在iPhone的全屏模式下无法完美运行 [英] Draw lines a touches event not work perfectly on FullScreen mode in iphone
问题描述
我正在创建可成功在iphone上绘制的应用程序.但是,仅在状态栏中最初隐藏状态栏= myapp-info.plist中没有,否则,设置状态栏最初处于隐藏状态=是无法正常工作.我的视图控制器代码如下:
-(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 *)touch withEvent:(UIEvent *)event {mouseSwiped =否;UITouch * touch = [触摸anyObject];如果([touch tapCount] == 2){drawImage.image = nil;返回;}lastPoint = [touch locationInView:self.view];//lastPoint.y-= 20;}-(void)viewDidAppear:(BOOL)动画{//[UIApplication sharedApplication] .statusBarHidden = NO;}-(void)touchesMoved:(NSSet *)touch withEvent:(UIEvent *)event {mouseSwiped =是;UITouch * touch = [触摸anyObject];CGPoint currentPoint = [触摸locationInView:self.view];currentPoint.y-= 20;//仅适用于'kCGLineCapRound'UIGraphicsBeginImageContext(self.view.frame.size);//Albert Renshaw-Apps4Life[drawImage.image drawInRect:CGRectMake(0,0,drawImage.frame.size.width,drawImage.frame.size.height)];//最初为self.frame.size.width,self.frame.size.height)];CGContextSetLineCap(UIGraphicsGetCurrentContext(),kCGLineCapRound);//kCGLineCapSquare,kCGLineCapButt,kCGLineCapRoundCGContextSetLineWidth(UIGraphicsGetCurrentContext(),5.0);//尺寸CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(),0.0,1.0,0.0,1.0);//R,G,B和Alpha的值CGContextBeginPath(UIGraphicsGetCurrentContext());CGContextMoveToPoint(UIGraphicsGetCurrentContext(),lastPoint.x,lastPoint.y);CGContextAddLineToPoint(UIGraphicsGetCurrentContext(),currentPoint.x,currentPoint.y);CGContextStrokePath(UIGraphicsGetCurrentContext());drawImage.image = UIGraphicsGetImageFromCurrentImageContext();UIGraphicsEndImageContext();lastPoint = currentPoint;mouseMoved ++;如果(mouseMoved == 10){mouseMoved = 0;}}-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {UITouch * touch = [触摸anyObject];如果([touch tapCount] == 2){drawImage.image = nil;返回;}if(!mouseSwiped){//如果颜色==绿色UIGraphicsBeginImageContext(self.view.frame.size);[drawImage.image drawInRect:CGRectMake(0,0,drawImage.frame.size.width,drawImage.frame.size.height)]];//最初为self.frame.size.width,self.frame.size.height)];CGContextSetLineCap(UIGraphicsGetCurrentContext(),kCGLineCapRound);//kCGLineCapSquare,kCGLineCapButt,kCGLineCapRoundCGContextSetLineWidth(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 {//如果没有超级视图,则释放视图.[super didReceiveMemoryWarning];//释放所有未使用的缓存数据,图像等.}-(void)viewDidUnload {[self setDrawImage:nil];[self setMy_view:nil];//释放主视图的所有保留子视图.//例如self.myOutlet = nil;}-(void)dealloc {[my_view版本];[drawImage发布];[super dealloc];}
此代码在没有全屏模式的情况下也可以正常运行.否则,不能像下面的输出一样工作:
请任何人帮助我们提供任何代码或示例...!
谢谢..
从
-(void)viewDidLoad 中移动
drawImage.frame = self.view.frame;
code>方法
到
-(void)viewWillAppear:(BOOL)动画
应该在viewWillAppear或viewDidAppear中进行任何几何调整.
I am create app to draw on iphone Sucessfully.But,it's work only set Status bar is initially hidden = No in myapp-info.plist.else if,set Status bar is initially hidden=yes don't working Perfectly.My viewcontroller code is Below:
- (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.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[my_view release];
[drawImage release];
[super dealloc];
}
This Code working perfectly on without fullScreen mode.else,does not working like Below output:
Please any one help me with us any code or examples...!
Thanks..!
Move drawImage.frame = self.view.frame;
from
- (void)viewDidLoad
method
to
-(void)viewWillAppear:(BOOL)animated
Any geometry adjustments should be made in viewWillAppear or viewDidAppear.
这篇关于画线触摸事件在iPhone的全屏模式下无法完美运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!