2011-11-03 3 views
-1

나는 이미지를 반복하고 싶습니다.하지만 코드를 실행하면 "MainViewController가 setneedsDisplay에 응답하지 않을 수 있습니다"라는 경고와 함께 충돌하고 "uiviewController가 initwithFrame에 응답하지 않을 수 있습니다"라는 오류가 발생합니다. 여기 내 코드가있다. 당신이 그것을 얻을이 시도 두 번째 경고가 당신의 할당 문에 관한 [self.view setNeedDisplay]를 호출 할 필요가 그래서 사전에setneedsdisplay do draw draw

#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); 

    } 

감사합니다 ..

+0

UIViewController와 UIView를 혼동하고 있습니다. – jrturton

답변

1

setNeedDisplays는 .... UIView의 방법입니다 :

self = [super initWithFrame:frame]; 

if(self){ 
//... 
}