setneedsdisplay 不绘制

发布于 2024-12-13 14:45:57 字数 1593 浏览 0 评论 0原文

我想一次又一次地重复图像。但是当我运行我的代码时,它崩溃并显示警告“MainViewController 可能不会响应 setneedsDisplay”以及“uiviewController 可能不会响应 initwithFrame”。这是我的代码。

  #import "MainViewController.h"


 @implementation MainViewController
 @synthesize car,road;

 UIImage *currentImage;

 int tileOffset=0;

  -(void)awakeFromNib{
[[UIApplication sharedApplication]setStatusBarHidden:YES withAnimation:NO];
[car setAlpha:0];
[road setAlpha:0];
currentImage=[UIImage imageNamed:@"Road3.png"];


[NSTimer scheduledTimerWithTimeInterval:(.1) target:self selector:@selector(onTimer)
                             userInfo:nil repeats:YES];

[NSTimer scheduledTimerWithTimeInterval:(.01) target:self selector:@selector(onTimerRoad) userInfo:nil repeats:YES];

}

 -(void)onTimerRoad{
tileOffset+=1;
[self setNeedsDisplay]; //here Get the warning
 }
 -(void)onTimer{
[self update1];

 }

 -(void)update1{

[self updateRoad];
 }
-(void)updateRoad{
[self randomRoadUpdate];
 }

-(void)randomRoadUpdate{

CGPoint oldPosition=road.center;
road.center=CGPointMake(oldPosition.x, oldPosition.y+1);

   }

 -(id)initWithFrame:(CGRect)frame{
if(self=[super initWithFrame:frame]){//here get warning
}


return self;
 }

  -(void)drawRect:(CGRect)rect{

CGImageRef image=CGImageRetain(currentImage.CGImage);
CGRect imageRect;

imageRect.origin=CGPointMake(160, 240);
imageRect.size=CGSizeMake(320, 480);

CGContextRef uicontext=UIGraphicsGetCurrentContext();

CGContextClipToRect(uicontext, CGRectMake(0, 0, rect.size.width, rect.size.height));
CGContextDrawTiledImage(uicontext, imageRect, image);

   }

提前致谢..

I want to repeat an image again and again.But when i run my code it crashes with a warning "MainViewController may not respond to setneedsDisplay" and also"uiviewController may not respond to initwithFrame". Here is my code.

  #import "MainViewController.h"


 @implementation MainViewController
 @synthesize car,road;

 UIImage *currentImage;

 int tileOffset=0;

  -(void)awakeFromNib{
[[UIApplication sharedApplication]setStatusBarHidden:YES withAnimation:NO];
[car setAlpha:0];
[road setAlpha:0];
currentImage=[UIImage imageNamed:@"Road3.png"];


[NSTimer scheduledTimerWithTimeInterval:(.1) target:self selector:@selector(onTimer)
                             userInfo:nil repeats:YES];

[NSTimer scheduledTimerWithTimeInterval:(.01) target:self selector:@selector(onTimerRoad) userInfo:nil repeats:YES];

}

 -(void)onTimerRoad{
tileOffset+=1;
[self setNeedsDisplay]; //here Get the warning
 }
 -(void)onTimer{
[self update1];

 }

 -(void)update1{

[self updateRoad];
 }
-(void)updateRoad{
[self randomRoadUpdate];
 }

-(void)randomRoadUpdate{

CGPoint oldPosition=road.center;
road.center=CGPointMake(oldPosition.x, oldPosition.y+1);

   }

 -(id)initWithFrame:(CGRect)frame{
if(self=[super initWithFrame:frame]){//here get warning
}


return self;
 }

  -(void)drawRect:(CGRect)rect{

CGImageRef image=CGImageRetain(currentImage.CGImage);
CGRect imageRect;

imageRect.origin=CGPointMake(160, 240);
imageRect.size=CGSizeMake(320, 480);

CGContextRef uicontext=UIGraphicsGetCurrentContext();

CGContextClipToRect(uicontext, CGRectMake(0, 0, rect.size.width, rect.size.height));
CGContextDrawTiledImage(uicontext, imageRect, image);

   }

Thanks in advance..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

≈。彩虹 2024-12-20 14:45:57

setNeedDisplays 是 UIView 的一个方法......所以你需要调用 [self.view setNeedDisplay] 第二个警告是关于你的赋值语句,尝试这个来解决它:

self = [super initWithFrame:frame];

if(self){
//...
}

setNeedDisplays is a method for UIView.... So you need to call [self.view setNeedDisplay] the second warning is about your assignment statement, try this to get it out:

self = [super initWithFrame:frame];

if(self){
//...
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文