2014-05-11 2 views
-1

나는 게임을하고 나는 그것을 중심 (보다는 이미 화면에 표시되는 버튼에 도달 할 때 뷰로드 및 중지 할 때 화면에 슬라이드 재생 버튼을 얻기 위해 노력하고 있어요 뷰가로드 될 때).만들기 버튼을 슬라이드

내가있는 viewDidLoad 함수에 다음 코드를 가지고 :

순간에 발생
- (void)viewDidLoad 
{ 

[super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 

while(playButton.center.x != 71) 
    playButtonTimer = [NSTimer scheduledTimerWithTimeInterval:0.002 target:self selector:@selector(playButtonMove) userInfo:nil repeats:YES]; 

} 

모두는 내가 응용 프로그램을 실행할 때, 화면은 검은 색 유지 나는 응용 프로그램을 닫을 때, 창이 나타납니다 Xcode 말하는 '메모리 오류로 인해 종료되었습니다'.

편집

:

-(void)playButtonMove { 
playButton.center = CGPointMake(playButton.center.x - 1, playButton.center.y); 
} 
+0

왜 투표가 실패합니까? ... –

답변

2

제거 : 여기 내 playButtonMove 기능입니다

while(playButton.center.x != 71) 
    playButtonTimer = [NSTimer scheduledTimerWithTimeInterval:0.002 target:self selector:@selector(playButtonMove) userInfo:nil repeats:YES]; 

그리고 파일이 추가 : 앱은 당신 때문에 영원히 실행

- (void)viewDidAppear:(BOOL)animated { 
    [UIView animateWithDuration:.25 animations:^{ 
     playButton.center = CGPointMake(71, playButton.center.y); 
    }]; 
} 

화재가 발생할 수 있기 전에 playbuttontimer를 재 할당하십시오. 이 때문에 while 문은 항상 true가됩니다. 기본적으로 귀하의 모든 앱은 현재 충돌이 발생할 때까지 수천, 수천 개의 NSTimers를 생성합니다. 애니메이션에 사용해서는 안됩니다. 애플의 애니메이션 API를 사용하십시오.