2011-03-17 7 views
1

나는 시작 직후에 재생되기를 원하기 때문에 viewDidLoad에 넣은 애니메이션 (이미지 배열)을 가지고 있습니다. viewDidLoad 애니메이션 후에도 UIWebView에서 webview를 보여주고 싶습니다. 애니메이션은 재생됩니다 (UIImage가 만들어지지 않은 이유가 있습니다).하지만 완료 후에는 제거 할 수 없습니다. 나는 타이머를 넣고 슈퍼 뷰에서 애니메이션을 제거하려고했지만 제거하는 대신 앱을 종료하고 메인 페이지로 돌아갑니다.완료 후 viewDidLoad에서 애니메이션 제거

-(void)viewDidLoad 
{ 
    UIImage *first = [UIImage imageNamed:@"panda1.png"]; 
    animation = [[UIImageView alloc] initWithImage:first]; 
    animation.animationImages = [NSArray arrayWithObjects: first, 
            [UIImage imageNamed:@"panda2.png"], 
            [UIImage imageNamed:@"panda3.png"], nil]; 

    animation.animationRepeatCount = 4; 
    animation.animationDuration = 2; 
    [animation startAnimating]; 

    [self.view addSubview:animation]; 

    //set timer to remove animation from view 
    NSTimer *timer; 
    timer = [NSTimer scheduledTimerWithTimeInterval: 3 
          target: self 
         selector: @selector(removeAnimation:) 
         userInfo: nil 
         repeats: NO]; 

    //for loading the image at start up 
    NSString *urlAddress = @"http://projects.seng.uvic.ca/most_recent.php"; 
    NSURL *url = [NSURL URLWithString:urlAddress]; 
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 

    //load the request in the UIWebView 
    [webView loadRequest:requestObj]; 

}

//removes the animation from subview 
- (void) method: (NSTimer*) theTimer 
{ 
    [animation release]; 
    [animation removeFromSuperview]; 
} 

답변

1

그것은 당신이 선택하는 셀렉터 (removeAnimation:) 및 방법 당신이 보여주고있다 (method:)처럼 보인다는 같은 이름되지 않습니다.

더 쉬운 방법은 다음과 같이 뭔가를하는 것입니다 :

-(void)viewDidLoad 
{ 
    UIImage *first = [UIImage imageNamed:@"panda1.png"]; 
    animation = [[UIImageView alloc] initWithImage:first]; 
    animation.animationImages = [NSArray arrayWithObjects: first, 
            [UIImage imageNamed:@"panda2.png"], 
            [UIImage imageNamed:@"panda3.png"], nil]; 

    animation.animationRepeatCount = 4; 
    animation.animationDuration = 2; 
    [animation startAnimating]; 

    [self.view addSubview:animation]; 
    [self performSelector:@selector(removeAnimation) withObject:nil afterDelay:8.0]; 


    //for loading the image at start up 
    NSString *urlAddress = @"http://projects.seng.uvic.ca/most_recent.php"; 
    NSURL *url = [NSURL URLWithString:urlAddress]; 
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 

    //load the request in the UIWebView 
    [webView loadRequest:requestObj]; 
} 

- (void)removeAnimation 
{ 
    [animation removeFromSuperview]; 
    [animation release]; 
} 

안녕하세요, 나는 팬더입니다.

+0

oops는 누락 된 함수 이름을 알지 못했습니다. (아직도이 mac 키보드에 익숙해 져 있습니다.) 함수 이름을 추가하면 내 문제가 해결되었습니다. – panda

0

UIImageView는 애니메이션이 중단 될 때 위임자 콜백을 제공하지 않는다고 생각합니다.

그래서, 당신이 다음과 같은 질문 방식을 사용한다면 : 는 How to create a multistage UIImageView animation?

이것은 또한 타이머에 대한 필요성을 제거합니다.

마지막으로, viewDidLoad는 최소한 데이터 셋과 뷰를 설정하는 곳으로 문서화되었습니다. 애니메이션을 원할 때 호출 할 수있는 것은 아닙니다. 나는 "viewWillAppear"또는 "viewDidAppear"를 사용하여 사물을 움직입니다.

관련 문제