2013-07-09 2 views
0

내 응용 프로그램이 배경을 입력하면 응용 프로그램이 포어 그라운드로 돌아갈 때 다시 시작하지 않고 작은 문제가 있습니다.응용 프로그램이 전경 ios를 입력하면 애니메이션 응용 프로그램을 다시 시작

@implementation startViewController 

-(void)animation { 

    UIImage*img1 = [UIImage imageNamed:@"wolk2.png"]; 
    image1 = [[UIImageView alloc]initWithImage:img1]; 
    image1.frame = CGRectMake(0, 0, 400, 200); 

    UIImage*img2= [UIImage imageNamed:@"wolk1.png"]; 
    image2 = [[UIImageView alloc]initWithImage:img2]; 
    image2.frame = CGRectMake(0, 0, 220, 100); 

    [self.imageView addSubview:image1]; 
    [self.imageView addSubview:image2]; 
    [[self imageView]sendSubviewToBack:image1]; 
    [[self imageView]sendSubviewToBack:image2]; 



    CGFloat a = (CGFloat) (100); 
    CGFloat b = (CGFloat) (100); 
    CGFloat a1 = (CGFloat) (50); 
    CGFloat b1 = (CGFloat) (350); 
    CGPoint startPointOne=CGPointMake(a,b); 
    CGPoint startPointTwo=CGPointMake(a1,b1); 
    image1.center=startPointOne; 
    image2.center=startPointTwo; 

    [UIView beginAnimations:nil context:NULL]; 
    [UIView setAnimationDuration:20]; 
    [UIView setAnimationCurve: UIViewAnimationCurveLinear]; 
    [UIView setAnimationRepeatAutoreverses:YES]; 
    [UIView setAnimationRepeatCount:100000]; 

    CGFloat c = (CGFloat) (700); 
    CGFloat d = (CGFloat) (100); 
    CGPoint endPointOne=CGPointMake(c,d); 
    image1.center = endPointOne; 


    [UIView commitAnimations]; 

    [UIView beginAnimations:Nil context:NULL]; 
    [UIView setAnimationDuration:30]; 
    [UIView setAnimationCurve: UIViewAnimationCurveLinear]; 
    [UIView setAnimationRepeatAutoreverses:YES]; 
    [UIView setAnimationRepeatCount:100000]; 

    CGFloat c1 = (CGFloat) (650); 
    CGFloat d1 = (CGFloat) (350); 
    CGPoint endPointTwo=CGPointMake(c1,d1); 
    image2.center = endPointTwo; 
    [UIView commitAnimations]; 
} 

그런 다음 응용 프로그램에서 내가 가진 대리인이 입력 :

나는이 시도

- (void)applicationDidBecomeActive:(UIApplication *)application 
    { 
start = [[startViewController alloc]init]; 
     [start animation]; 

    } 

는하지만이 작동하지 않았다

, 그래서 나는 애니메이션을 다시 시작하려면 어떻게해야합니까? self.startViewController이 속성은

- (void)applicationDidBecomeActive:(UIApplication *)application { 
    [self.startViewController animation]; 
} 

:

- (void)applicationDidBecomeActive:(UIApplication *)application { 
     start = [[startViewController alloc]init]; 
     [start animation]; 
} 

당신은이 같은 수의 startViewController의 기존 인스턴스를 호출해야합니다 :

+0

http://stackoverflow.com/questions/7568567/restoring-animation-where-left-off-when-app-resumes-from-background – stosha

답변

0

당신은 당신의 startViewController의 새 인스턴스를 만들 수 있습니다 여기서 startViewController의 인스턴스를 유지합니다.

+0

죄송합니다. 작동하지 않았습니다. – Thymen

+0

어느 부분입니까? 'startViewController'의 인스턴스에 대한 정확한 참조를 유지하고있을 것이라고 확신하십니까? – rckoenes

관련 문제