在我的應用程序中,我使用動畫進行啓動屏幕。 這個動畫在延遲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];
}
你應該重新考慮你的起動程序,反正。應用程序應儘可能快地啓動,以便讓用戶體驗「多線程感覺」。一些開發人員花費數天的時間讓App開始更快。如果用戶第一次看到它,動畫可能會很好。經過2或3次創業之後,它可能會很糟糕。 – 2011-03-10 11:20:47