2011-03-10 75 views
0

在我的應用程序中,我使用動畫進行啓動屏幕。 這個動畫在延遲5秒後停止。 但是如果用戶中斷(觸摸)動畫應該停止,我希望在5秒之前。通過觸摸事件停止飛濺動畫

對於動畫我寫:

- (void)applicationDidFinishLaunching:(UIApplication *)application 
{ 
    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

    // Array to hold jpg images 
    imageArray = [[NSMutableArray alloc] initWithCapacity:IMAGE_COUNT]; 

    // Build array of images, cycling through image names 

    imageArray = [NSMutableArray arrayWithObjects: [UIImage imageNamed:@"f1.jpg"], [UIImage imageNamed:@"f2.jpg"], [UIImage imageNamed:@"f3.jpg"], [UIImage imageNamed:@"f4.jpg"], [UIImage imageNamed:@"f5.jpg"], [UIImage imageNamed:@"f6.jpg"], nil]; 

    // Animated images - centered on screen 
    animatedImages = [[UIImageView alloc] 
         initWithFrame:CGRectMake(
               (SCREEN_WIDTH/2) - (IMAGE_WIDTH/2), 
               (SCREEN_HEIGHT/2) - (IMAGE_HEIGHT/2) + STATUS_BAR_HEIGHT, 
               IMAGE_WIDTH, IMAGE_HEIGHT)]; 
    animatedImages.animationImages = [NSArray arrayWithArray:imageArray]; 

    // One cycle through all the images takes 1.5 seconds 
    animatedImages.animationDuration =1; 

    // Repeat forever 
    animatedImages.animationRepeatCount = -1; 

    // Add subview and make window visible 
    [window addSubview:animatedImages]; 
    [window makeKeyAndVisible]; 

    // Start it up 
    //animatedImages.startAnimating; 
    [animatedImages startAnimating]; 


    // Wait 5 seconds, then stop animation 
    [self performSelector:@selector(stopAnimation) withObject:nil afterDelay:5.0]; 

} 

- (void)stopAnimation 
{ 
    [animatedImages stopAnimating]; 
    [window addSubview:viewController.view]; 
    [window makeKeyAndVisible]; 
} 
+0

你應該重新考慮你的起動程序,反正。應用程序應儘可能快地啓動,以便讓用戶體驗「多線程感覺」。一些開發人員花費數天的時間讓App開始更快。如果用戶第一次看到它,動畫可能會很好。經過2或3次創業之後,它可能會很糟糕。 – 2011-03-10 11:20:47

回答

1

不是一個問題

呼叫stopAnimation方法tochesBegan方法這樣

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    YourAppDelegate *obj=(YourAppDelegate *)[[UIApplication sharedApplication] delegate]; 
    [obj stopAnimation]; 
} 
+0

好的,我實現了,但控制不會觸及touchBegan函數。我在appDelegate中編寫所有上面的代碼。 – 2011-03-10 11:07:52

+0

見編輯答案。 – Ishu 2011-03-10 11:09:36

+0

但問題是控制不會繼續tochesBegan函數。順便說一句,第一行是怎麼回事。 – 2011-03-10 11:14:30