setneedsdisplay не рисовать

#iphone #cgrect #setneedsdisplay

#iPhone #cgrect #setneedsdisplay

Вопрос:

Я хочу повторять изображение снова и снова.Но когда я запускаю свой код, он выходит из строя с предупреждением «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);

   }
  

Заранее спасибо..

Комментарии:

1. Вы путаете UIViewController с UIView.

Ответ №1:

setNeedDisplays — это метод для UIView…. Итак, вам нужно вызвать [self.view setNeedDisplay] второе предупреждение о вашем операторе присваивания, попробуйте это, чтобы получить его:

 self = [super initWithFrame:frame];

if(self){
//...
}